I have the following String:
"(X,Y,Z),(A,B,C),(R,S,T)"
I want to split this into a multi-dimensional array:
arr[0] = [x,y,z]
arr[1] = [a,b,c]
arr[2] = [r,s,t]
so that:
arr[0][1] = y, arr[0][2] = z, etc.
I can do it by stripping the first and last parens, splitting on "),(" and then looping through that array and doing another split. But I feel dirty, unpure, like a stripper (pun intended) in a backalley bar ... is there a cleaner way?
Maybe some LINQ to the rescue?
I'm using C#.
string data = "(X,Y,Z),(A,B,C),(R,S,T)";
string[][] stringses = data.Trim('(', ')')
.Split(new[] {"),("}, StringSplitOptions.RemoveEmptyEntries)
.Select(chunk => chunk.Split(','))
.ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With