What I am doing is reading in from a text file, and then storing the contents in a 2D array, but my array is off by one at each row and column. Maybe this is simple and I am just not seeing it?
The contents of my text file:
0007,0007,0007,0007,0007,
0007,0007,0007,0007,0007,
0007,0007,0007,0007,0007,
0007,0007,0007,1707,0007,
0007,0007,0007,0007,0401
When my array is returned, the value 17 is located at [3,3]...it should be [4,4]. Below is my code. I've spent to much time on this already, could someone please help?
public int[,] Generate(string inputFilePath)
{
if (File.Exists(inputFilePath))
{
Dictionary<string, int> counts = GetRowAndColumnCounts(inputFilePath);
int rowCount = counts["row_count"];
int columnCount = counts["column_count"];
returnArray = new int[rowCount, columnCount];
using (StreamReader sr = File.OpenText(inputFilePath))
{
string s = "";
string[] split = null;
for (int i = 0; (s = sr.ReadLine()) != null; i++)
{
split = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
for (int j = 0; j < columnCount; j++)
{
returnArray[i, j] = int.Parse(split[j].Substring(0,2));
}
}
}
}
else
{
// throw new FileDoesNotExistException("Input file does not exist");
}
return returnArray;
}
1707which is on the 4th line and 4th column is actually at index 3,3.