Im trying to read a CSV into a 2d array, where the rows of CSV are the rows of the array, and the columns are defined by the separating commas in the file. It will be a rectangular array.
any help would be ace!
You can read the file contents in line by line then use string.Split() to convert each row into a string array.
The following works provided that the array definitely has the same number of rows as columns:
string filePath = @"C:\Users\Dan\Documents\test.txt";
StreamReader sr = new StreamReader(filePath);
string[,] strArray = null;
int Row = 0;
string Line = sr.ReadLine().Split(',');
if (Row == 0)
strArray = new string[Line.Length, Line.Length];
for (int column=0; column<Line.Length; column++)
strArray[Row, column] = Line[column];