Parsing CSV with TextFieldParser with fields containing double quotes

247 views Asked by At

I'm trying to parse a file that contains fields that seem valid to me but fail using C# TextFieldParser. Here is an example of problematic line:

"abc","def","this is container "A" in room","another field"

using TextFieldParser parser = new(Filename);
parser.TextFieldType = FieldType.Delimited;
parser.SetDelimiters(RawFileDelimiter);
parser.HasFieldsEnclosedInQuotes = true;

while (!parser.EndOfData)
{
    string[] fields = parser.ReadFields();

    // do some validation
}

I did not find any parameter in TextFieldParser to go through this case. I guess I could use regex to parse it but that will make the whole thing much more complicated. Am I missing something obvious?

0

There are 0 answers