Format Code Now
/
Encode & decodeCSV Escape and Unescape Next: HTML Decode String ›

Escape and Unescape CSV Values Line by Line

ED-31

Paste a value to wrap it in quotes and double its inner quotes, the way RFC 4180 describes. Use Escape each line for a column of values, or Unescape to read a quoted value back.

Runs in your browser. Nothing is uploaded.

One value, or one value per line

Result

How to use it

  1. Paste your text. For Escape each line, put one value on every line.
  2. Pick the delimiter your CSV file uses: comma, semicolon, tab or pipe.
  3. Click Escape, Escape each line or Unescape.
  4. Copy the result into your CSV file.

When a field needs quotes

A CSV field must be quoted when it contains the delimiter, a double quote or a line break. Inside the quotes, each double quote is doubled, so He said "hi" becomes "He said ""hi""". Values without those characters are returned unchanged unless you turn on Always add quotes. A value with spaces at the start or end can also be quoted, which goes beyond the RFC but stops some readers from trimming it.

One value or one per line

Escape treats everything you paste, including line breaks, as one field. Escape each line splits the input at line breaks and escapes each line on its own, which suits pasting a column from a spreadsheet. Unescape works on a single quoted field and gives errors for a missing closing quote, text after it, or an unquoted value that holds the delimiter. It does not parse a whole CSV file.

Error messages and what to do

MessageWhat it meansFix
The quoted value never endsA value starts with a double quote but has no closing one.Add the closing quote, and double any quote inside the value.
Text after the closing quoteCharacters follow a closing quote, so the quote ended the value too early.Write inner quotes as two double quotes.
inside an unquoted valueA double quote appears in a value that does not start with one.Wrap the whole value in quotes and double the inner quotes.

Questions people ask

How do I escape a comma in CSV?

Put the whole field in double quotes. A field such as Smith, John becomes "Smith, John", and a parser then treats the comma as part of the value. This tool does that automatically when it finds the chosen delimiter.

How do I escape a double quote in CSV?

Double it and wrap the field in quotes. The text 5" pipe becomes "5"" pipe". This is the rule in RFC 4180, and most spreadsheet programs and parsers read it correctly.

Can a CSV field contain a line break?

Yes, if the field is in double quotes. Escape keeps line breaks inside one quoted field. Escape each line does not, because it treats every line break as the start of a new value.

Does this work with semicolons or tabs?

Yes. Pick the delimiter in the list. Values are quoted only when they contain that delimiter, a quote or a line break, so a comma in a semicolon-separated file stays unquoted.

Can I unescape a whole CSV file here?

No. Unescape reads one quoted value at a time. For whole files use a CSV converter, which splits rows and columns. Pasting a full row here gives an error, because the delimiters between fields sit outside quotes.

About this tool

Escape treats the whole input, line breaks included, as a single CSV field. Escape each line treats every line as its own field and returns one escaped field per line, which is handy for a column of values; line breaks inside a value are not possible in that mode. Quotes are added only when the value holds the delimiter, a double quote or a line break (or always, if you choose), and inner quotes are doubled, as in RFC 4180. Unescape handles one quoted field, not a full row or file, and reports missing or stray quotes.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.