Hi all,
I am able to pull data from a CSV file into a string array using the following code.
public static string[,] ReadCSV(string filename)
{
//Read Text
string whole_file = System.IO.File.ReadAllText(filename);
//Split into Lines
whole_file = whole_file.Replace('\n', '\r');
string[] lines = whole_file.Split(new char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries);
//Calucluate Rows and Columns
int num_rows = lines.Length;
int num_cols = lines[0].Split(',').Length;
//Allocate Array
string[,] values = new string[num_rows, num_cols];
//Load Array
for (int r = 0; r < num_rows; r++)
{
string[] line_r = lines[r].Split(',');
for (int c = 0; c < num_cols; c++)
{
values[r, c] = line_r[c];
}
}
//Return Values
return values;
}
This was based off an online example, so I'm not entirely sure what's happening here. I'm assuming that the data is stored as a string array with two required indexes [row, column]... Though I've never seen that, so it causing a bit of confusion.
Anyway, all the data in the CSV is a double, and I need the array to contain only doubles. How would I go about either converting the entire array, or populating it as a double in the first place?