4 ms·
CSV is fine. If you care about edge cases, implement RFC 4180: https://www.rfc-archive.org/getrfc.php?rfc=4180 https://www.rfc-archive.org/getrfc.php?rfc=4180
by hedora 5y ago
CSV is fine. If you care about edge cases, implement RFC 4180:
https://www.rfc-archive.org/getrfc.php?rfc=4180 https://www.rfc-archive.org/getrfc.php?rfc=4180
If you don't, then split each line on ",". Problem solved.
If you find tab delimited easier to read (as I do), then check out the IANA spec for TSV files:
https://www.iana.org/assignments/media-types/text/tab-separated-values https://www.iana.org/assignments/media-types/text/tab-separa...
It's easier to parse than CSV. Unfortunately, you have to decide how to handle newlines and tabs yourself (probably as \n, \t, with \\ for backslashes).
- makeworld 5y ago> If you don't, then split each line on ",". Problem solved. And the millionth bad CSV parser is born.
- naikrovek 5y agoyeah the "CSV is fine" bit scared me. people think they know what everyone is doing and why; in reality (where these problems actually need to be solved) no one knows.
- hedora 5y agoMore than the millionth, I'm sure. If you know your input doesn't have commas (for example, because you generated it) and the code is throwaway, then splitting on comma is fine. But, yeah, I prefer tab delimited, since "no commas" is painful, and data that contains quotes leads to scenarios where the crappy CSV I generated can't be parsed by RFC 4180 parsers.
- gnulinux 5y ago> If you don't, then split each line on ",". Problem solved. What? Real data contains '"' quote character too. That doesn't work.
- hedora 5y agoRead the RFC I linked. It handles all the characters.