A CSV file is made up of many records, where a record is a single entire line in the file. Each new line is signified with the record delimiter (typically a carriage return and line feed character, CRLF or \r\n). A record is made up of many fields, each which a seperated by the field delimiter (typicallay a comma or a tab character).
- Each record is located on a different line, and each line is seperated by the carriage return and line break characters (the record delimiter).
The last record in the file may or may not have a record delimiter at the end of it.
xxx,yyy,zzz CRLF (record delimiter on last line)
xxx,yyy,zzz (no record delimiter on last line)
There is an optional header record at the top of the file (the first line), with the same format as the rest of the records. The header contains names/descriptions of the fields in the file.
Field1Name, Field2Name, Field3Name
- White-space (space and tab characters) are considered part of the field, and shall be preserved (i.e. not stripped) when parsing CSV files.
There is no “official” standard for CSV files, however, RFC 4180 stands as the defacto standard (it formally registers the MIME type “text/csv”.