I have a grid of two-digit numbers written as a string delimited with newlines and spaces, e.g.:
string grid = "58 96 69 22 \n" +
"87 54 21 36 \n" +
"02 26 08 15 \n" +
"88 09 12 45";
I would like to split it into a 4-by-4 array, so that I can access it via something like separatedGrid[i, j]
. I know I can use grid.Split(' ')
to separate the numbers in each row, but how do I get a 2-D array out of it?
Yes use
split
like this:And if you want a 2-D Array:
The result:
So what you want is to convert a delimited multi-Line String into a 2D-Array: