CSV Formatieren RFC 4180
Gemein Formatieren und MIME Typ für Comma-Separated Werte per RFC 4180.
Record Structure
RFC 4180 defines a CSV file as a sequence of records, one per line, terminated by CRLF. Each record consists of fields separated by commas, and the last record may or may not have a trailing CRLF. A field containing commas, quotes, or line breaks must be enclosed in double quotes. Within a quoted field, double quotes are escaped by doubling them. This simple grammar enables broad interoperability but many real-world files deviate from the standard.
- field separator
- Comma separates fields
- record separator
- CRLF terminates a record
- quoting
- Double quotes wrap fields with special chars
- escaped quote
- Doubled double quote inside quoted field
a,b,c row1\r\nrow2 "a,b" "say ""hi""" Header Row
The standard does not mandate a header row, but common convention places field names in the first record. Applications must agree out-of-band whether the first row is a header, because the format itself cannot distinguish. Some libraries auto-detect headers heuristically, but this is unreliable. Explicit configuration of header presence avoids parsing ambiguity.
Common Deviations
Many CSV producers use semicolons in locales where the comma is the decimal separator, and some use tabs or pipes. Line endings vary between LF and CRLF across platforms. Some files omit quoting around fields that contain only spaces. A robust parser should accept configurable delimiters and line endings, and always quote fields containing the delimiter on output to maximize compatibility.