I have the following code that produces a MatchCollection:
var tmp3 = myregex.Matches(text_to_split);
The Matches in tmp3 are strings such as 93.4 and -276.2. What I really need is to convert this MatchCollection into an array of doubles. How can this be done?
You could use the double.Parse method to convert a string to double:
and if you are a LINQ and functional programming fan like me you could save a useless loop and directly convert your
MatchCollectionto anIEnumerable<double>:and if you needed a static array an additional
.ToArray()call might be necessary:If you want a safe conversion you could use the double.TryParse method but if your regular expression is good enough and you have ensured that the string is in a proper format you should be OK.