Parsing .csv file into 2d array
I'm trying to parse a csv file into a 2d array in C#. I'm having a very
strang issue, here is my code:
string filePath = @"C:\Users\Matt\Desktop\Eve Spread
Sheet\Auto-Manufacture.csv";
StreamReader sr = new StreamReader(filePath);
data = null;
int Row = 0;
while (!sr.EndOfStream)
{
string[] Line = sr.ReadLine().Split(',');
if (Row == 0)
{
data = new string[Line.Length, Line.Length];
}
for (int column = 0; column < Line.Length; column++)
{
data[Row, column] = Line[column];
}
Row++;
Console.WriteLine(Row);
}
My .csv file has 87 rows, but there is a strange issue in the execution
where it will read the first 15 rows into the data array exactly as
expected but when it gets down to the data[Row, column] = Line[column];
line for the 16th time it seems to just break out of the entire
loop(without meeting the sr.EndOfStream condition) and not read any more
data into the data array. Can anyone explain what might be happeneing?
No comments:
Post a Comment