Separating Comma-Separated Strings
I have a string containing the value "12,13"
I want 2 strings from this string i.e
s1 = 12
and
s2 = 13
how can I separate in asp.net C#?
I have not开发者_如何学JAVA much time to google it that's why I am posting it here. Hope anyone can answer this.
Thanks in advance
Try this:
string firstString = "12,13";
string[] values = firstString.Split(',');
string s1 = values[0];
string s2 = values[1];
string numbersText ="12,13"
string[] numbers= numbersText.Split(',');
if(numbers.Length >= 2) // check length of array if you not sure about text before access items of it
{
string s1 =numbers[0];
string s1 =numbers[1];
}
You can use string.Split() method
example:
string text = "12,13";
string[] parts = text.Split(',');
string s1 = parts[0]; // "12"
string s2 = parts[1]; // "13"
精彩评论