6 ms·
What is the proper way to encode the quotes? I'm playing around with writing a Livejournal data dump reader and will have to do the quote dance pretty soon. I
by akinder 13y ago
What is the proper way to encode the quotes? I'm playing around with writing a Livejournal data dump reader and will have to do the quote dance pretty soon. In LJ files they are encoded like so:
col1,col2,col3,"Longer data and somethin ""with"" quotes",col5
- tbrownaw 13y agoYes, that's how they're supposed to be. Any field with quotes, or commas, or newlines in the data needs to have quotes around it. Any quotes in the data need to be escaped by preceding them with another quote.
- justinator 13y agoFrom what I understand, you're basically right, but you're basically right only in a sense that that's what most people do. There's no "CSV Data Format" spec. It's all just what most people agree on, most of the time. Unless someone has another idea.
- steveklabnik 13y agotext/csv is defined in RFC 4180: https://tools.ietf.org/html/rfc4180 https://tools.ietf.org/html/rfc4180
- nemetroid 13y agoStrictly, the definition in RFC 4180 mandates ASCII which makes it unusable for many purposes. I guess there's nothing practical stopping you from using another encoding though.
- steveklabnik 13y ago> Common usage of CSV is US-ASCII, but other character sets defined > by IANA for the "text" tree may be used in conjunction with the > "charset" parameter. http://www.rfc-editor.org/rfc/rfc6657.txt http://www.rfc-editor.org/rfc/rfc6657.txt https://www.iana.org/assignments/character-sets/character-sets.xhtml https://www.iana.org/assignments/character-sets/character-se...