Can anyone tell me how a csv-file is structured because i need to code a parser.
3 Answers
In a CSV-File the Columns are seperated by ',', the Rows by Newlines respectively. The First Row contains the indentifiers for the columns. If there is any occurence of delimiters in the content, it need to be escaped by an '"' or the content needs to be literal. RFC: https://www.rfc-editor.org/rfc/rfc4180
That depends. CSV is a rather ill-defined format, so you can't generally assume very much about the format. For example, in Germany, columns are usually separated by semi-colons and not commas.

- 115,121
- 27
- 131
- 155
-
In Germany, the columns in comma-separated files are separated with semi-colons? How curious. – Don Branson Oct 02 '12 at 19:29
-
2Well, more accurately - Excel will use your machines regional settings to determine the separator. For most continental european countries it's a semi colon. Not the brightest idea in the history of computing, if you ask me. – troelskn Oct 03 '12 at 06:35
-
Well, perhaps it's a bit more bright when you realise we use a decimal comma instead of a decimal point. Image having to escape every single decimal number in a CSV... – Mr47 Oct 12 '12 at 12:30
-
True, but I was referring to the idea of having the (apparently) same file format actually have more than one (incompatible) implementation. Makes it impossible to parse the file without knowing which country it originated from. I'd prefer just escaping everything all the time - Nobody writes it by hand anyway. – troelskn Oct 12 '12 at 17:20
https://www.rfc-editor.org/rfc/rfc4180
There are a lot of parsers that already exist. And I strongly recommend using them, unless you are comfortable writing a grammar that matches the spec, and letting a parser generator create the parser for you. And even then, you'll have to deal with options such as column headers.