I am using C# to develop a Small app which converts csv file to a readable format.
Below is the of sample in CSV file
"Symbol","Date","Expiry","Strike Price","Open","High","Low","Close","LTP"
"5000","6000","4500","45855" ............
over 300 lines like this.
public List<string[]> parseCSV(string path)
{
List<string[]> parsedData = new List<string[]>();
try
{
using (StreamReader readFile = new StreamReader(path))
{
string line;
string[] row;
while ((line = readFile.ReadLine()) != null)
{
row = line.Split(','); // <<< this ',' is not working
parsedData.Add(row);
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return parsedData;
}
According to the data, I should get new line at LTP, but it’s not happening and more than than I am getting result as single line . If add the list ie parseData it is showing as single row.
As others have stated rolling your own CSV parser is difficult and error prone. My personal preference lies with the FileHelpers library and to show you how good and easy it is I have included a working example with your data: