I am working on a CSV parser using the C # TextFieldParser class.
My CSV data is divided by,, and the string is enclosed in the character " .
However, sometimes the data row cell may also have " , which apparently causes the parser to throw an exception.

This is my C # code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using Microsoft.VisualBasic.FileIO; namespace CSV_Parser { class Program { static void Main(string[] args) {
This is the contents of my test.csv file:
" dummy test"s data", b , cd,e,f gh,ij
What is the best way to work with " in my row cell data?
UPDATE
Based on Tim Schmelter's answer, I changed my code to the following:
static void Parse_CSV(String Filename) { using (TextFieldParser parser = new TextFieldParser(Filename)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); parser.HasFieldsEnclosedInQuotes = false; parser.TrimWhiteSpace = true; while (parser.PeekChars(1) != null) { var cleanFieldRowCells = parser.ReadFields().Select( f => f.Trim(new[] { ' ', '"' })); Console.WriteLine(String.Join(" | ", cleanFieldRowCells)); } } }
It seems that the following is being created (correctly):

Is this the best way to handle quoted string with quotation marks?
source share