g.pickardou
g.pickardou

Reputation: 35853

How to handle quotation mark in data when using CsvHelper?

I am successfully reading almost all lines from my .tsv (tab separated) file. However when the data itself contains quotation mark CsvHelper calls BadDataFound handler

For example:

nm10296809\tWilliam "Billy" Cohen\t1\t1\tactor\tmore data

The character data itself is not enclosed to quotation in the data file.

When I configure my own BadDataFound hander, then the argument clearly shows that the problem is the 2nd field containing William "Billy" Cohen

Question

How to handle the quotation marks as data, within my 2nd field? As a workaround I can write a typconverter to filter out those lines by replacing the quotation mark with something special, then replacing back, but that smells a bit...

What I tried so far:

config.Quote = '\"'

Upvotes: 0

Views: 3022

Answers (1)

Panagiotis Kanavos
Panagiotis Kanavos

Reputation: 131364

In previous CsvHelper versions there was an IgnoreQuotes config setting:

config.IgnoreQuotes=true;

In version 20.0 it was removed and replaced by the Mode property and CsvMode.NoEscape :

config.Mode = CsvMode.NoEscape;

Upvotes: 1

Related Questions