c# - How to get Lumenworks CsvReader to correctly parse data with unescaped double quotes and commas from a CSV file -
i trying parse csv file using lumenworks csvreader. each data point wrapped in double quotes, however, values contain unescaped double quotes within data, , other values contain commas within data. the issue facing when parse csvreader, columns ending in file due lumenworks seeing these characters delimiters.
as read below, i've handled issue unescaped double quotes using known solution, results in issue of columns being generated data commas inside.
example: 2 columns (each wrapped in quotes), unescaped double quotes in 1 of data points
"name","description"
"bob","i "cool" guy"
when attempting perform csvreader.readnextrecord(), instead of splitting 2 columns, splits 4 columns:
- bob
- i a
- cool
- guy
i've used solution provided in reading csv having double quotes lumenwork csv reader , works quite well!
this how i've implemented it:
char quotingcharacter = '\0' ; char escapecharacter = quotingcharacter; char delimiter = ','; using (csvreader csvreader = new csvreader(reader, false, delimiter, quotingcharacter, escapecharacter, quotingcharacter, valuetrimmingoptions.all)) {.... csvreader.readnextrecord(); ...}
however, when implement fix csv file, creates same issue columns have commas inside:
example: 2 columns (each wrapped in quotes), commas in 1 of data points, after implementing double quote workaround
"name","description"
"bob","i related suzie, betty, , tommy"
with aforementioned solution implemented, csvreader not know read commas part of data. instead of 2 columns, left 4 columns:
- bob
- i related suzie
- betty
- and tommy
so question is: how allow lumenworks csvreader work around bad data , have interpret unescaped double quotes data itself? how can done in way doesn't cause commas within data interpreted delimitation?
Comments
Post a Comment