# Comma separator: lists to CSV-style text and back

> Exactly how lines become a comma-separated list (and back), how quoting and escaping work (quotes are doubled, as CSV and SQL expect), and where it still falls short of a real CSV parser.

- Tool: [Comma Separator](https://toolsg.com/en/comma-separator)
- Language: en (available: en, zh, ms, ta)
- Last verified against official sources: 2026-10-20
- Source site: ToolSG — a planning guide, not official or financial advice. Cite the agencies listed under Sources.

## Key figures at a glance

| Fact | Value | Source |
| --- | --- | --- |
| Directions | Lines to commas, and commas to lines — Chosen with the Direction menu. |  |
| Joiner | Comma plus one space — Items are joined with `, `; an optional trailing comma can be added. |  |
| Quote escaping | The quote character is doubled — `it's` becomes `'it''s'` in single quotes and `say "hi"` becomes `"say ""hi"""` in double quotes, as SQL and CSV expect. |  |
| Comma to lines | Quote-aware splitting — A quoted field may contain commas and doubled quotes; `1,200` still becomes two items. |  |

## Lines to comma-separated

In the default direction the tool does this to the text, in your browser:

1. Split into lines (`\r\n`, `\r` and `\n`).
2. Trim each line's surrounding whitespace and discard empty lines.
3. Optionally wrap each item in single or double quotes.
4. Join with a comma and one space (`, `). Tick **Trailing separator** to add a final comma.

Spaces inside an item are kept: `a b c` stays one item. An empty input gives an empty result.

Example input, with an indented line, an empty line and a Windows line ending:

```
apple
  banana 
(empty line)
cherry
it's
```

| Quote option | Output |
| --- | --- |
| No quotes | `apple, banana, cherry, it's` |
| Single quotes | `'apple', 'banana', 'cherry', 'it''s'` |
| Double quotes, trailing comma | `"apple", "banana", "cherry", "it's",` |

## How quotes are escaped

When quoting is on, the tool doubles any occurrence of the same quote character inside an item: `it's` in single quotes becomes `'it''s'`; `say "hi"` in double quotes becomes `"say ""hi"""`. The other kind of quote is left alone (`it's` in double quotes stays `"it's"`) and backslashes are not touched (`back\slash` stays `back\slash`).

This is what both common destinations expect:

- **CSV.** RFC 4180 escapes a double quote inside a quoted field by doubling it: `"b""bb"`. A backslash is just an ordinary character in CSV. Use double quotes for CSV.
- **Standard SQL / PostgreSQL.** A single quote in a string constant is written as two single quotes (`'it''s'`). With `standard_conforming_strings` on (the default since PostgreSQL 9.1) a backslash in an ordinary constant is literal, so a backslash escape such as `'it\'s'` would be broken. Use single quotes for SQL.

> **Tip:** Use this tool for lists of simple values such as IDs, tags or e-mail addresses. For values that come from users, do not paste the result straight into SQL or CSV. Use your database's parameterised queries or a CSV library, which also protects against injection.

## Comma-separated to lines

Choosing the other direction does the reverse:

1. Walk through the text and split at every comma, except inside quotes: a piece that starts with a single or double quote (after optional spaces) runs to the matching closing quote, so commas inside it do not split it.
2. Inside a quoted piece, two quote characters in a row become one literal quote, so `"say ""hi"""` gives `say "hi"`.
3. Trim unquoted pieces, drop empty pieces and join with new lines.
4. If a quote is opened and never closed, the whole text is split on plain commas instead and the quote characters at the ends of each piece are stripped, so one stray apostrophe such as `'tis` cannot swallow the rest of the list.

Examples:

| Input | Output |
| --- | --- |
| `a, b,,'c', "d" ,e` | `a`, `b`, `c`, `d`, `e` on separate lines |
| `'it''s', "x, y", z` | `it's`, `x, y`, `z` |
| `"say ""hi""", "ok"` | `say "hi"`, `ok` |
| `1,200, 3,400` | `1`, `200`, `3`, `400` |
| `a;b` | `a;b` (only commas split) |
| `'tis, fine` | `tis`, `fine` (the unclosed quote is ignored) |

The tool is still not a full CSV parser: it treats single quotes as quotes too, only the ASCII comma separates items, a quoted field that contains a line break comes out as two lines, and numbers with thousands separators are split. For real CSV files use a spreadsheet or a proper parser.

## Common mistakes

- Pasting the result into a SQL query built from untrusted values. The quotes are valid SQL, but parameterised queries are still the safe way.
- Using double quotes for SQL: SQL string constants use single quotes, while double quotes suit CSV.
- Expecting the separator to be only a comma. The joiner is a comma and a space, so remove the spaces afterwards if your format needs `a,b,c`.
- Forgetting that blank lines are dropped, so a blank row will not become an empty list entry.

## Related tools

[Text sorter](https://toolsg.com/en/text-sorter) sorts and de-duplicates the lines before you join them. [Remove line breaks](https://toolsg.com/en/remove-line-breaks) joins lines with spaces instead. [Text repeater](https://toolsg.com/en/text-repeater) makes a repeated list quickly. [Word counter](https://toolsg.com/en/word-counter) counts the lines and words in your list.

## Frequently asked questions

**Is my text sent to a server?**

No. Everything runs in your browser using JavaScript. Nothing you type or paste is uploaded, logged or stored anywhere.

**Is there a length limit?**

There is no fixed limit — the practical ceiling is your browser's memory. Documents of tens of thousands of words are handled comfortably.

**Does it handle non-English text?**

Yes, text in any language is kept as typed. The tool only splits on the plain comma (,), so a Chinese comma (，) or enumeration comma (、) is not treated as a separator.

**Does it change my original text?**

No. Your input stays exactly as you typed it; the result is produced separately so you can adjust the options and compare.


## Sources

- [RFC 4180 — Common Format and MIME Type for CSV Files](https://www.rfc-editor.org/rfc/rfc4180#section-2) — Quotes inside quoted fields are escaped by doubling.
- [PostgreSQL — String constants](https://www.postgresql.org/docs/current/sql-syntax-lexical.html) — A single quote in a string constant is written as two single quotes; backslashes are literal by default.
