ocaml-csv icon indicating copy to clipboard operation
ocaml-csv copied to clipboard

delimiter in field?

Open brianjmurrell opened this issue 5 years ago • 3 comments

I seem to be having inconsistent output and it seems to be because in my CSV file, I have (single quoted) string fields that have the delimiter inside them. So:

'foo','bar','foo,bar'

Can this be handled in some way?

brianjmurrell avatar Nov 21 '19 13:11 brianjmurrell

Single quotes are not valid CSV delimiters:

# Csv.input_all (Csv.of_string {|'foo','bar','foo,bar'|});;
- : Csv.t = [["'foo'"; "'bar'"; "'foo"; "bar'"]]
# Csv.input_all (Csv.of_string {|"foo","bar","foo,bar"|});;
- : Csv.t = [["foo"; "bar"; "foo,bar"]]

Chris00 avatar Nov 21 '19 17:11 Chris00

The single quotes are not the delimiter, a comma is. The single quotes are wrapping fields which can have a comma in them.

brianjmurrell avatar Nov 21 '19 17:11 brianjmurrell

Sorry, I expressed badly. Single quotes cannot be used to enclose fields, only double quotes can.

Chris00 avatar Nov 21 '19 17:11 Chris00