Hello!
How do I convert a string, formatted as following:
string str="1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16"
to a multidimensional array, so that:
arr[0,0]=1
arr[0,1]=2
arr[0,2]=3
arr[0,3]=4
arr[1,0]=5
and so on.
The string can have different sizes.
Thanks!
Loading
VulpesPosted Nov 30, 2012, 5:55 AM
However, if (as the question suggests) you then want to move it to a rectangular array of ints, you can do so - less elegantly - as follows:
string str = "1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16";
Notice that, if the string arrays have different lengths (which they don't in the example), then the second dimension of the rectangular array is taken to be the maximum length of the string arrays. This means that 'unfilled' elements in the rectangular array will have their default values of 0.
Blocked AccountPosted Nov 30, 2012, 2:39 AM
try this
string str = "1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16";
String[][] MultiArray = str.Split(';').Select(t => t.Split(' ')).ToArray();
for accessing the value either you have to write like that or through loop.
string val = MultiArray[0][2];