Simplify string parsing?

I’ll get an input that (could) look something like this: (0,1,2)(3,4,5)(6,7,8) (The numbers can be anything from 0-9)

I’ve done something like:

string[] splitParts = input.Split(new char[] { '(', ')', '[', ']', '{', '}' }, 4, System.StringSplitOptions.RemoveEmptyEntries); bool[] bools = new bool[9]; float[] floats = new float[9]; string[] firstPart = splitParts[0].Split(new char[] { ',' }, 3); for (int i = 0; i < firstPart.Length; i++) { bools[i] = float.TryParse(firstPart[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out floats[i]); some_value = (floats[0], floats[1], floats[2]); } string[] secondPart = splitParts[1].Split(new char[] { ',' }, 3); for (int i = 0; i < secondPart.Length; i++) { bools[i + 3] = float.TryParse(secondPart[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out floats[i + 3]); some_value = (floats[3], floats[4], floats[5]); } string[] thirdPart = splitParts[2].Split(new char[] { ',' }, 3); for (int i = 0; i < thirdPart.Length; i++) { bools[i + 6] = float.TryParse(thirdPart[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out floats[i + 6]); some_value = (floats[6], floats[7], floats[8]); } 

There is a clear repeating pattern here. I’ve tried putting it in a for loop, but could not get it to work right. Any help? There can also be an additional parameter after the input which could look something like this: (0,0,0)(1,1,1)(2,2,2) another_value

But that’ll come in later, but any ideas on how to get this done? I appreciate any help, if further information is needed, I can provide them

submitted by /u/ggeasy2
[link] [comments]

Leave a Reply