I\'ve got a simple application that opens a tab-delimited text file, and inserts that data into a database.
I\'m using this CSV reader to read the data: http://www.codep
I recently solved a similar issue, and although CsvReader was working properly on all but a few lines of my TSV file, what solved my problem in the end was setting a customDelimiter
in the constructor of CsvReader
public static void ParseTSV(string filepath)
{
using (CsvReader csvReader = new CsvReader(new StreamReader(filepath), true, '\t')) {
//if that didn't work, passing unlikely characters into the other params might help
//using (CsvReader csvReader = new CsvReader(new StreamReader(filepath), true, '\t', '~', '`', '~', ValueTrimmingOptions.None)) {
int fieldcount = csvReader.FieldCount;
//Does not work, since it's read only property
//csvReader.Delimiter = "\t";
string[] headers = csvReader.GetFieldHeaders();
while (csvReader.ReadNextRecord()) {
for (int i = 0; i < fieldcount; i++) {
string msg = String.Format("{0}\r{1};", headers[i],
csvReader[i]);
Console.Write(msg);
}
Console.WriteLine();
}
}
}