I got a string like, "house1_508_17.5_end003". Basically I want get 508, 17.5 out of this string.
Asked
Active
Viewed 65 times
-3
-
3There are plenty of questions on getting values from a string. Please read some and see if ideas there are applicable to your case. If not - make sure to update your post with what approaches you've tried and how to verify if code provided in answer actually answers the question. Also please check methods of `String` class - you may find something useful there. – Alexei Levenkov Jan 18 '16 at 01:49
-
You could take a look on `string.Split` and `double.TryParse` these are what you need – Ian Jan 18 '16 at 02:36
1 Answers
1
You can split on the _
character.
string s = "house1_508_17.5_end003";
string[] digits = s.Split('_');
foreach (string digit in digits)
{
Console.WriteLine(digit);
}

sdc
- 2,603
- 1
- 27
- 40
-
Please see the [documentation](https://msdn.microsoft.com/en-us/library/system.string.split(v=vs.110).aspx) for `String.Split`. The documentation has good examples. This question might also be considered a duplicate. See this [existing question](http://stackoverflow.com/questions/7559121/c-sharp-splitting-strings) – sdc Jan 18 '16 at 09:20