3

I have input that people will probably say "that's not really CSV", but I still have to parse it. (using Papa Parse)

comma is the delimiter. backslash is the escape. comma, double quote, backslash, r and n (to denote newlines) can all be escaped. There is no "quoting" of strings.

so... I see data like:

this is one\, field,1/2\" bolt,this is text with \\ and a new line \r\n embedded

and I want:

[0] this is one\, field
[1] 1/2\" bolt
[2] this is text with \\ and a new line \r\n embedded

but I'm getting

[0] this is one\
[1] field
[2] 1/2\" bolt
...

I can deal with the other \x things in post processing... I'd just like to get it to handle \, correctly.

I've tried the obvious values of quoteChar and escapeChar with no luck.

oh... and the Donate link is broken on https://www.papaparse.com/ if Matt Holt is listening.

Fuzzy
  • 190
  • 7

1 Answers1

1
const parsed = window.Papa.parse(csvText, {
  escapeChar: '\\',
});

Seems like default escape character is ", but it can be overidden in the paramters.

Upd. though now that I look at it, it does not seem to work with your case. It only did fix an issue I had of 2.5\","Shell being considered single value because " was interpreted as escape character for ,.

I'm starting to get a feeling that the only way to escape coma is to enclose the field in the quotes.

Hope someone will post the right answer eventually...

Klesun
  • 12,280
  • 5
  • 59
  • 52