c# - Parsing Mixedt CSV-File with TextFieldParser -


hello have problem parse csv-file. csv-file delimited | character . far good. 1 field enclosed " char. example

field1|field2|"field3"|field4 

when set

hasfieldsenclosedinquotes

to true become exception otherwise parsing of csv-file goes wrong. can me here.

i haven't seen culture, '|' csv separator...

all in all,

var line = "field1|field2|\"field3\"|field4"; var pattern = string.format("{0}(?=([^\"]*\"[^\"]*\")*[^\"]*$)", regex.escape("|"));  //{0} in pattern csv separator. current use system.globalization.cultureinfo.currentculture.textinfo.listseparator var splitted = regex.split(line, pattern, regexoptions.compiled | regexoptions.explicitcapture);  foreach (var s in splitted)     console.writeline(s); 

output:

field1 field2 "field3" field4 

pattern designed split single line csv file using specified separator characters. includes handling of quotes, etc. hope you.


Comments

Popular posts from this blog

python - cx_oracle unable to find Oracle Client -

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -