Help needed with string operation
-
Hi I need a bit of help. I have this string: "10 > 8 > 99> 34" From this string, how can I extract all the numbers? Basically, when I receive the above string, I want to get every number out of it and do something with that number. Thanks
-
Hi I need a bit of help. I have this string: "10 > 8 > 99> 34" From this string, how can I extract all the numbers? Basically, when I receive the above string, I want to get every number out of it and do something with that number. Thanks
string[] numberstrings = mystring.split('>'); int[] numbers = new int[numberstrings.Length]; for (int i=0; i<numberstrings.Length; i++) { numbers[i] = int.Parse(numberstrings[i]); }
You might want to make sure that all the strings that come out of the split really are numbers through so you should probably wrap the line in the for loop with a try/catch statement to be safe. -- modified at 10:52 Monday 5th June, 2006