darylbewise
Programmer
Hi all,
I have built a CSV parser that will convert each line of a csv cod into a string[].
This works for the majority of csv documents. However when a column within the CSV contains a comma, the split will not split the columns out corrently.
For Example:
csv file:
1, 2, 3, "4,5"
output I want:
y[0] = 1
y[1] = 2
y[2] = 3
y[3] = "4,5"
output i get:
y[0] = 1
y[1] = 2
y[2] = 3
y[3] = "4
y[4] = 5"
Any ideas how I can get this issue resolved?
I have built a CSV parser that will convert each line of a csv cod into a string[].
Code:
if (File.Exists(path))
{
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using (StreamReader sr = new StreamReader(fs))
{
while (!sr.EndOfStream)
{
string[] y = sr.ReadLine().Split(',');
}
}
}
}
This works for the majority of csv documents. However when a column within the CSV contains a comma, the split will not split the columns out corrently.
For Example:
csv file:
1, 2, 3, "4,5"
output I want:
y[0] = 1
y[1] = 2
y[2] = 3
y[3] = "4,5"
output i get:
y[0] = 1
y[1] = 2
y[2] = 3
y[3] = "4
y[4] = 5"
Any ideas how I can get this issue resolved?