Reputation: 1376
I have a string like
string str = "123.1.1.QWE";
string[] seqNum = textBox1.Text.Split('.');
I want to split the string at the last . value and have to split into two strings only like
seqNum[0]="123.1.1";
seqNum[1]="QWE";
How can I split it into two strings at the last index.
Thanks in advance.
Upvotes: 2
Views: 8739
Reputation: 11
string str = "123.1.1.QWE";
string[] seqnum = new string[2];
foreach (char ch in str)
{
if (char.IsNumber(ch) || ch == '.')
{
}
else
{
int indx = str.IndexOf(ch);
seqnum[0] = str.Substring(0, indx).ToString();
seqnum[1] = str.Substring(indx,str.Length-indx).ToString();
break;
}
}
// output
// seqnum[0]=123.1.1.
// seqnum[1]=QWE
Upvotes: 0
Reputation: 959
string str = "123.1.1.QWE";
int index = str.LastIndexOf(".");
string[] seqNum = new string[] {str.Substring(0, index), str.Substring(index + 1)};
Upvotes: 12