T
tk
I have a text file that I need to import into a datatable. It is comma
delimited (and the fields are enclosed in quotes). I use the following code
to read the file.
reader = new StreamReader(txtFilePath.Text.Trim());
string data = reader.ReadToEnd();
string linedelimeter = "\r\n";
string delieter = ",";
string[] rows = data.Split(linedelimeter.ToCharArray());
foreach (string r in rows)
{
string[] items = r.Split(delimeter.ToCharArray());
}
The problem is if one of the fields has a comma in it, the split function
seperates it into 2 fields, even thou the field is in quotes. Is there a
way to handle the comma in the field besides manually parsing each line?
Thanks,
Tim
delimited (and the fields are enclosed in quotes). I use the following code
to read the file.
reader = new StreamReader(txtFilePath.Text.Trim());
string data = reader.ReadToEnd();
string linedelimeter = "\r\n";
string delieter = ",";
string[] rows = data.Split(linedelimeter.ToCharArray());
foreach (string r in rows)
{
string[] items = r.Split(delimeter.ToCharArray());
}
The problem is if one of the fields has a comma in it, the split function
seperates it into 2 fields, even thou the field is in quotes. Is there a
way to handle the comma in the field besides manually parsing each line?
Thanks,
Tim