CSVHelper does not parse my Tab delimited CSV file

Viewed 5699

I am trying to read a tab delimited CSV file and parse it with CSVHelper.

I have the following :

 _reader = new StreamReader(_stream);
 _csvReader = new CsvReader(_reader);
 _csvReader.Configuration.Delimiter = "\t";

but the reader fails to recognize and parse the file correctly

Any ideas ?
What are the possible delimiters with CSVHelper ?

4 Answers

So for some reason, it turns out that it works only when I do the following:

 _reader = new StreamReader(_stream);

 CsvHelper.Configuration.Configuration myConfig = new 
     CsvHelper.Configuration.Configuration();

 _csvReader.Configuration.Delimiter = "\t";

 _csvReader = new CsvReader(_reader, myConfig);

I encountered a similar problem parsing a tab delimited file in vb, didn't work for me until I replaced "\t" with vbTab

My code:

Imports System.Globalization
Imports System.IO
Imports CsvHelper
Imports CsvHelper.Configuration
Imports CsvHelper.Configuration.Attributes

Public Class TabDelimetedReader
    Public Shared Function ReadFile(path As String) As IEnumerable(Of TabFileDefinition)

        Dim config = New CsvConfiguration(CultureInfo.InvariantCulture,
            hasHeaderRecord:=False,
            delimiter:=vbTab)

        Using reader As StreamReader = New StreamReader(path)
            Using tsv = New CsvReader(reader, config)
                Return tsv.GetRecords(Of TabFileDefinition).ToList
            End Using
        End Using

    End Function
End Class

I ran into similar issue with a tab delimited file- and I could not get Delimiter = "\t" to work...

Then I added Encoding = Encoding.UTF8 in the configuration, then it worked!

Related