So I'm working on a project in Unity in C# and I have to get information from a csv file. I made a test file to develop the code, but I have a little issue.
The test csv file contains (3 rows, each have 5 columns):
5,9,12,53,67
8,24,33,49,71
10,16,28,64,88
I'm using the code below to read in to a jagged array. When I print to the console (with the debug.log function) the lengths of each row, I get the correct answer. But if I use a for loop, it only gets the first row's length, but not the other two. How is this possible? As far as I know for loop should work with it perfectly. No errors.
Any ideas?
Thanks for your help!
The code:
StreamReader test = new StreamReader("D:/Unity/Projects/.../Assets/Resurces/test.csv");
var testLines = new List<string[]>();
int row = 0;
while (!test.EndOfStream)
{
string[] Line = test.ReadLine().Split(',');
testLines.Add(Line);
row++;
}
var data = testLines.ToArray();
Debug.Log(data.Length);
Debug.Log(data[0].Length);
Debug.Log(data[1].Length);
Debug.Log(data[2].Length);
for (int i=0; i<data.Length; i++)
{
Debug.Log("i: " + i);
Debug.Log(data[i].Length);
}
What I get on the console:
3
5
5
5
i: 0
5
i: 1
i: 2