Reputation: 47
I'm working in C# and trying to parse out the floats on each side of the "w" from the following string:
"10.3w20.5"
I want to have the floats available to use as floats in an equation. How do I accomplish this?
I tried splitting the string by length but then realized that the values on each side could be variable in length.
Upvotes: 0
Views: 312
Reputation: 62256
The only thing to add to avalable answers, is what usually people forget to mantion in conversion mnagement. If you're going to operate in multiculture environment, pay attention on Culture you use to store and convert data to.
public static float ToSingle(
string value,
IFormatProvider provider
)
I would say, even if you're not going to operate in multiculture environment, it's always a good to pay attention on this.
Upvotes: 3
Reputation: 45101
How about:
var floats = "10.3w20.5".Split('w').Select(s => Convert.ToSingle(s));
Upvotes: 3