Erm.. text can contain tabs, too. This problem was solved so, so long ago when all the various ANSI/ASCII/whatever encodings were compiled by specifically reserving not one but two characters precisely to serve as field and record delimiters.
0x30 and 0x31 solved not only the problem of having commas or tabs in your text preventing you from treating them as field delimiters, but also allowing you to include new lines and carriage returns in your fields, too!
0x30 is the unit separator (aka field delimiter) and 0x31 is the record separator (aka, well, the record separator).
I _believe_ there was a record key on some standardized keyboard layout back in the day, too.
Edit: sorry, they are decimal, not hex. Thanks @jrochkind1
I have spent some time working with MARC 21 binary encoding (used for library cataloging records) which uses ASCII 0x1D, 0x1E, and 0X1F as delimiters. I would def not call it appreciably more _convenient_ than a more modern 'text' record format. If it has benefits, convenience isn't really one of them.
I know XML et al are frustrating, but I'd rather see them than a "creative" solution. It seems like 60% of the reason we still have to deal with archaic flat formats is support for Excel.
Granted, that’s the whole point, but it also makes authoring and instruction harder. (And we all know how many programmers are really just competent copy-pasters.)
Yes, but CSV files are record collections, they are not in 99% of cases recursive like that.
If a column contains escaped secondary documents, there's something wrong.
Also most CSV parsers support quotation marks and escaping to get around the comma and new line et al problems. eg:
"full name", "address"
"Homer Simpson", "742 Evergreen Terrace,\nSpringfield"
"Bart \"El Barto\" Simpson", "742 Evergreen Terrace,\nSpringfield"
Granted it's not the prettiest and some spreadsheets really love to break the formatting upon save (cough Microsoft Excel cough) but it does work.As a side note, the best spreadsheet I've found for manipulating CSV data without breaking the formatting upon saving was OpenOffice Calc. This was a few years back before the LibreOffice fork was created as I've thankfully not needed to deal with CSV files large enough to warrant a full blown spreadsheet editor, but I would assume LibreOffice Calc would behave the same.
full name,address
Homer Simpson,"742 Evergreen Terrace,
Springfield"
"Bart ""El Barto"" Simpson","742 Evergreen Terrace,
Springfield"
(Omitted optional quotes for fields that don't need them). Quotes are escaped with "", and line breaks don't need escaping, they just have to be in a quoted field. And there is no space after a comma, except you want that space to be part of the field's value.> Omitted optional quotes for fields that don't need them
I think it's good policy to always wrap your contents in quotes regardless of whether you have a delimiter that needs quoting. And in fact many CSV marshallers will do just this.
> And there is no space after a comma
That was added purely for readability on HN. I agree it's not how you'd normally marshal the contents.
Been there. Use a lib that implements a documented standard, even a bad one. Only problem is Excel, which basically standardizes on CSV and occasionally mangles your data into malformed dates because reasons anyways.
Stop using "punctuation" when you are attempting to "delimit" text. Use a character that is not punctuation, specifically designed for "field delimiter" purposes.
Trying to do two things at once is ridiculous.