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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
YousefPosted Mar 30, 2007, 9:46 PM
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