Q: read number from a string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have TEST_1_str1, TEST_100_str2, TEST_1010_str3, TEST is fixed, how could
you read 1, 100, 1010 between _ from these kind of strings?
Thanks,
Jim.
 
You could use the split operator then test for ints.

string s = "TEST_1_str1, TEST_100_str2, TEST_1010_str3, TEST"
string [] sa = s.Split( '_' );

sa is a string array that contains the following information

sa[0] = "TEST"
sa[1] = "1"
sa[2] = "str1, TEST"
sa[3] = "100"
sa[4] = "str2, TEST"
....

You would step through each item in the array and check to see if it is an
int.

bill
 
Back
Top