5 ms·
> text.split("\n") I don't want to be negative but this will not work on CSV files that contain newlines inside columns. You should also implement escaping quo
by userbinator 13y ago
> text.split("\n")
I don't want to be negative but this will not work on CSV files that contain newlines inside columns. You should also implement escaping quotes - this is very important to ensure that the data can round-trip! Good for a first attempt, but as simple as CSV may look, there are subtle points that you should be aware of if you want to handle most if not all CSV out there. I've worked with lots of other implementations that get these little things wrong too, and it is particularly aggravating when CSV is supposed to be a pretty standard interchange format for tabular data. Please refer to RFC4180 for the details.
- deleted 13y ago[deleted]
- gcb0 13y agoyet, that is what most csv code does. heck, ms excell did that until a few versions ago.
- gav 13y agoMS Excel has supported CSV that had newlines in fields for a least a decade.
- EvanPlaice 13y agoMS Excel also defaults to using /r as the newline char on the OSX version (despite /r being obsolete in OSX since v10.1). It's true that CSV parsers have been around in various forms for a long time but 'complete' implementations in JavaScript haven't been available until recently.
- coldtea 13y ago>yet, that is what most csv code does. Not an excuse, and not really true if we're talking about libraries. Naive one-off implementations of readers maybe. >heck, ms excell did that until a few versions ago Nope, Excell, even from 14 years ago has an extensive panel for configuring how (encoding, terminator, etc) your csv file is, and can also handle newlines inside items just fine.
- deleted 13y ago[deleted]