- Home /
Parsing an odd string concatenation to float
Hello all,
I'm using c#.
I'm trying to parse out the floats on each side of the "w" from the following string.
Here is the string "10.3w20.5"
Want to have the floats available to use as floats in an equation.
I hope that makes sense ...
Comment
Answer by Rod-Green · Dec 21, 2011 at 08:18 AM
float[] SplitFloatPair(string p_source, char p_splitChar)
{
string[] splitFloats = p_source.Split(p_splitChar);
float[] result = new float[2]{ 0.0f, 0.0f };
if(splitFloats != null && splitFloats.Length == 2)
{
float.TryParse(splitFloats[0], out result[0]);
float.TryParse(splitFloats[1], out result[1]);
}
return result;
}
Call with:
SplitFloatPair("10.3w20.5", 'w');
Your answer
![](https://koobas.hobune.stream/wayback/20220613062250im_/https://answers.unity.com/themes/thub/images/avi.jpg)