First off i'm a bit of a novice at C#
So I have a CSV file with 11 columns and over 20,000 rows, its just a bunch of data from a sports tracking gps. What I want to do is be able to take that data from the CSV and load each column into a seperate collection, however I can't get it to work the way I want it.
I've spent ages searching up how to do this properly, but all i've managed to muster together this janky code that does load all the data into the collections, but will only let me load each piece of data into the collection as a string (not as decimal or char, which I need for some [yes I've tried delcaring the collections as decimal or char before]).
So what I need help with is being able to actually load the data from the CSV file into the collection as the data type I want, and if there's an easy way to skip the first 8 or so lines which are just headers.
The list of data types I require are as follows (in order of declared) decimal decimal char decimal char decimal string string decimal decimal string
Here is the code i'm currently using:
//Seprate class for all the collection declarations
public static class GPSdata
{
public static List<string> time = new List<string>(); //time (in seconds, advances by 0.2)
public static List<string> lat = new List<string>(); //Latitude
public static List<string> NS = new List<string>(); //North/South
public static List<string> lon = new List<string>(); //Longtitude
public static List<string> EW = new List<string>(); //East/West
public static List<string> knots = new List<string>(); //Speed in Knots
public static List<string> date = new List<string>(); //Date [ddmmyy]
public static List<string> sats = new List<string>(); //**No clue**
public static List<string> HDOP = new List<string>(); //Satelite Horizontal error
public static List<string> alt = new List<string>(); //Elevation (above msl)
public static List<string> rawSV = new List<string>(); //Space Vehicle
}
//Method for loading the CSV data into the collections
public void LoadCSV(string filepath)
{
using (StreamReader reader = new StreamReader(filepath))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
GPSdata.time.Add(values[0]);
GPSdata.lat.Add(values[1]);
GPSdata.NS.Add(values[2]);
GPSdata.lon.Add(values[3]);
GPSdata.EW.Add(values[4]);
GPSdata.knots.Add(values[5]);
GPSdata.date.Add(values[6]);
GPSdata.sats.Add(values[7]);
GPSdata.HDOP.Add(values[8]);
GPSdata.rawSV.Add(values[9]);
GPSdata.alt.Add(values[10]);
}
}
}
Also heres an example of the data from the file i'm reading off: 31350.2,3750.9188,S,14458.8652,E,7.98,50817,0,2.3,0,23 31350.4,3750.9204,S,14458.867,E,6.66,50817,0,2.3,0,23