I need to find the pattern from the following string and get the int32 bit values from number1,number2.
Example Input:“afsad fsdaf [25,33] fasdffa fasfasfa”
Example Input:“afsad fsdaf [25,33] fasdffa fasfasfa”
Know the answer? Post it. Somebody with the same question will find it here.
Yousef2 pointsPosted Mar 30, 2007, 5:46 PM EDT
int firstNumber;
int secondNumber;
string myString = "afsad fsdaf [25,33] fasdffa fasfasfa";
string strNumbers = myString.Substring(myString.IndexOf('[') + 1, myString.IndexOf(']') -myString.IndexOf('['));
char[] commaSep ={ ',' };
string[] numbers = strNumbers.Split(commaSep);
if (numbers.Length > 0)
firstNumber = int.Parse(numbers[0]);
if (numbers.Length > 1)
secondNumber = int.Parse(numbers[1]);
I've written a function called GetStringInBetween that can do the above for you, you can check this articles http://www.mycsharpcorner.com/Post.aspx?postID=15 for the source code.
You can also use Regular expressions, which are much compact.
Hope this helps