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column and number format?

A: 

For flat files i normaly use the http://www.codeproject.com/KB/database/filehelpers.aspx.

It might help you on this one...

Yves M.
+1  A: 

if you are the one making that map, then why not change your format to something more parse-able? It seems to me that just using ascii characters would be easiest, and then just parse it char by char into an array. probably easier to generate the map this way anyway.

..................................
......**************..............
.....******************...........
....***********************.......
....w******w************xx*.......

etc..

tenfour
How is that any more parsable than an array of numbers?
Dan Puzey
each char here is an element in the resulting map. in the OP's format, it's 1) difficult to read, and 2) there are a bunch of extra characters (mostly commas and whitespace). A text file is already a 2D array, so might as well take advantage of this similarity. And replace numbers with symbolic characters to make it more visual, just as a bonus.
tenfour
it's possible i misunderstand the OP. i assumed he's parsing a text file consisting of `map={.....}`. Considering the answer he accepted, it looks like this wasn't a question of parsing at all.
tenfour
+2  A: 

It doesn't really need "parsing" it's already in a nested Array.

So you can use it using standard for loops:

for (int row = 0; row < map.Length; row++)
{
  for (int col = 0; col < map[i].Length; col++)
  {
     Console.WriteLine(map[row][col]);
  }
}

And access any specific row by:

int rowNum = 5;
int colNum = 2;
Console.WriteLine(map[rowNum][colNum]);
badbod99
A: 

The map in the example is JSON. Just use a JSON deserialiser. For example: http://www.codedigest.com/CodeDigest/112-JSON-Serialization-and-Deserialization-in-ASP-Net.aspx

VeeWee
This isn't JSON.
Steve Cooper
it can be parsed as a JSOn array ;)
VeeWee
A: 

Are you looking for the C# code to create a multidimensional array? Here is the one for your example.

int[,] map = new int[25,100] { ... your array goes here... }

Mike