Guide
How to handle commas and quotes in a CSV file
The three characters that need quoting, how each is written, and what goes wrong when they are not.
Short answer
In CSV, a field that contains a comma, a double quote or a line break is wrapped in double quotes, and a double quote inside the field is written twice. RFC 4180 states these rules. A broker description such as EXAMPLE INC, CLASS A is a typical case: it becomes "EXAMPLE INC, CLASS A" in the file.
The rules
- RFC 4180, rule 6: "Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes."
- Rule 7: "If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double quote."
- Rule 5: if a field is not enclosed in double quotes, "double quotes may not appear inside the fields."
How a value is written
| The value contains | The value | Written in the file as |
|---|---|---|
| Nothing special | EXAMPLE INC | EXAMPLE INC |
| A comma | EXAMPLE INC, CLASS A | "EXAMPLE INC, CLASS A" |
| A double quote | Example "A" Shares | "Example ""A"" Shares" |
| A comma and a double quote | Example "A", Inc | "Example ""A"", Inc" |
| A line break | First line, then second | Wrapped in double quotes, with the line break kept inside the quotes (RFC rule 6 and its example) |
What goes wrong without it
An unquoted comma inside a field adds an extra field to that line. RFC 4180 says each line should contain the same number of fields throughout the file, so the row no longer matches the header, and everything after the comma lands in the wrong column. An unescaped double quote inside a quoted field closes the field early in the same way.
A quick check is to open the file in a plain text editor and look at a line with a comma in the text. If that field is not wrapped in double quotes, the file breaks rule 6.
Programs differ
RFC 4180 is an informational memo and says there is no formal specification of CSV. The RFC itself notes, in rule 5, that some programs, such as Microsoft Excel, do not use double quotes at all. A file from an unfamiliar source may not follow these rules, so it is worth looking at before it is relied on. See the CSV file page.
Common questions
- Do all fields need quotes?
- No. RFC 4180 says each field may or may not be enclosed in double quotes. Only fields with line breaks, double quotes or commas should be.
- How do I put a double quote inside a field?
- Enclose the field in double quotes and write the inner double quote twice, as in rule 7.
- What about a comma in a number?
- A number written as 1,250.00 contains a comma, so by rule 6 it needs double quotes. Writing it without the thousands separator avoids the problem.
- Can a field span several lines?
- Yes, if it is enclosed in double quotes. The RFC gives an example with a line break inside a quoted field.
What Statementizer does with this
Statementizer reads supported broker statement PDFs into rows you can review, and exports them to Excel or CSV. Descriptions with commas are one reason a CSV needs the quoting rules above.
See what Statementizer convertsRelated guides and formats
Sources
Every rule is quoted from RFC 4180, section 2, read on 2026-11-12. The table of examples applies those rules to invented values.
Verified on 2026-11-12 by the Statementizer Team.