How to Use the Comma Separator
- Paste a column into Values to Convert, one value per line. A column copied from Excel or Google Sheets has this form already. The result changes as you type.
- Under Convert, keep Lines to Commas to join the lines, or pick Commas to Lines to split a list into one value per line.
- Pick a Separator. Comma and space is the default; with Custom you can type any text, such as
::or-. - Under Quotes Around Each Value, pick Single for an SQL list of text values or Double for a CSV row. A quote mark inside a value is doubled.
- Under More Options, add text before and after the list, sort it, remove duplicates, or keep spaces and empty values.
- Select Copy List to copy the result exactly as shown. The line under the result has the number of values in and out and what was removed.
Example With Eight Cities on One Line
The example column has 8 cities, one per line. With the default settings they are joined into one line: Oslo, Lisbon, Vienna, Prague, Dublin, Madrid, Athens, Helsinki. With Comma picked as the separator, there are no spaces in the result, Oslo,Lisbon,Vienna,Prague,Dublin,Madrid,Athens,Helsinki, the form for a CSV row or a form field.
For an SQL query, paste the last names O'Brien, Smith, Garcia and Smith again, pick Single quotes, type ( and ) under More Options and turn on Remove duplicates. The result is ('O''Brien', 'Smith', 'Garcia'): the second Smith is gone, and the apostrophe in O’Brien is written twice so it counts as part of the name. Paste the list straight after IN in a query such as SELECT * FROM customers WHERE last_name IN ('O''Brien', 'Smith', 'Garcia');
With Commas to Lines picked, Single quotes and the same ( and ), the list ('O''Brien', 'Smith', 'Garcia') becomes three lines again: O’Brien, Smith, Garcia.
Separators and When to Use Them
Here are the values a, b and c on three lines with each separator. A tab appears as an arrow.
| Separator | Result | Common Use |
|---|---|---|
| Comma and space | a, b, c | Lists people read, SQL IN lists, tags |
| Comma | a,b,c | A CSV row, values for code or a form field |
| Semicolon and space | a; b; c | Email addresses for a mail program that wants semicolons |
| Semicolon | a;b;c | Numbers written with a decimal comma, such as 1,5 |
| Pipe | | a|b|c | Values that contain commas themselves |
| Tab | a → b → c | Values to paste into cells side by side in a spreadsheet |
| Space | a b c | Words or tags on one line |
When splitting with Comma and space, the list is split at every comma and one space after it is skipped, so a,b and a, b are both two values. Line breaks count as separators too, and a block of CSV rows becomes one cell per line.
Quotes and Values That Contain a Comma
A value such as Paris, France contains the separator, so in a plain join it would be read as two values. With no quotes picked, such values are put in double quotes, as in the CSV fields of RFC 4180, and any double quote inside them is doubled. With quotes picked, every value is in quotes, and the same quote mark inside a value is written twice. In SQL string constants the rule is the same, so O'Brien becomes 'O''Brien'. For JSON and JavaScript, pick the backslash under Quote Mark Inside a Value.
| Lines Pasted | Settings | Result |
|---|---|---|
Ada Lovelace / Paris, France / 5" screen | Comma and space, no quotes | Ada Lovelace, "Paris, France", "5"" screen" |
Ada Lovelace / Paris, France / 5" screen | Comma, double quotes | "Ada Lovelace","Paris, France","5"" screen" |
O'Brien / Smith / Garcia / Smith | Single quotes, ( and ), Remove duplicates | ('O''Brien', 'Smith', 'Garcia') |
red / green / say "hi" | Comma, double quotes, backslash, [ and ] | ["red","green","say \"hi\""] |
Quoted values are read back whole when splitting. The list apples, "pears, ripe", plums,, figs has 4 values, apples, pears, ripe, plums and figs, because the comma inside the quotes is part of the value and the empty value between the two commas is removed. Double quotes are read with None or Double picked; pick Single to read a list in single quotes.
Sorting, Duplicates and Empty Lines
Remove empty values and Trim spaces around values are on by default, so blank lines and extra spaces from a spreadsheet are left out of the list. With Remove duplicates on, the first copy of each value is kept and later ones that match exactly are removed, capitals included. For the addresses ann@example.com, bob@example.com, ann@example.com with one blank line, the result with Semicolon and space and Remove duplicates is ann@example.com; bob@example.com, and the line under the result is 4 lines in, 2 values out. Removed 1 empty value and 1 repeat.
In A to Z order, capitals and accents do not count and digits are compared as numbers, so item2 comes before item10. Sorted A to Z, the lines item10, Item2, item1, Éclair and apple become apple, Éclair, item1, Item2, item10. Z to A is the opposite order, and Reversed is the pasted order backward, with no sorting.
Comma Separated Lists in Excel
Excel 2019 and later, and Excel for Microsoft 365, have the TEXTJOIN function: the result of =TEXTJOIN(", ", TRUE, A1:A8) is the cells A1 to A8 joined with a comma and space, with empty cells skipped. The result of TEXTJOIN is the #VALUE! error when it would be longer than 32,767 characters, and it has no quotes, so a value with a comma in it is read as two values. To quote each value in Excel, join the quotes in the formula as well, or paste the column here and pick the quotes.
How Lists Are Converted to Commas and Back
In Lines to Commas, each line is one value. One line break at the very end is ignored, because a column copied from a spreadsheet ends with one. With Trim spaces around values on, spaces, tabs and no-break spaces are removed from both ends of each value. A value counts as empty when it has no characters or only spaces. Then duplicates are removed, the order is applied, each value is quoted where needed, and the values are joined with the separator, with the text before and after the list added to the ends.
In Commas to Lines, the text before and after the list is first removed from the ends, if it is there, and the list is read from left to right. A value that starts with the quote mark ends at the closing quote mark, and a doubled quote mark inside it, or one after a backslash with that option picked, is one quote mark. Spaces inside the quotes are kept. Any other value ends at the next separator or line break. A value with an opening quote and no closing quote is read as plain text.
With the same settings, a joined list split again has the same values, as long as quotes are picked or values with the separator are put in double quotes. A custom separator cannot contain a quote mark. The text is converted in your browser and never sent anywhere, and no word list is needed, so any values can be converted: numbers, email addresses, codes or words in any language.
FAQs
Q1. How Do I Convert a Column to a Comma Separated List?
To convert a column to a comma separated list, copy the column from your spreadsheet and paste it into the box with Lines to Commas picked. Each line becomes one value, so eight cities give Oslo, Lisbon, Vienna, Prague, Dublin, Madrid, Athens, Helsinki. Select Copy List to copy the line, ready to paste wherever you need it.
Q2. How Do I Add Quotes and Commas for an SQL IN Clause?
For an SQL IN clause, pick Single quotes, then type ( and ) under Text Before the List and Text After the List in More Options. The last names O’Brien, Smith and Garcia become ('O''Brien', 'Smith', 'Garcia'), with the apostrophe doubled as SQL requires, and the list fits straight after IN in the query.
Q3. What Happens When a Value Contains a Comma?
A value that contains a comma is put in double quotes when no quotes are picked, the way RFC 4180 writes CSV fields, so Paris, France is still one value: Ada Lovelace, "Paris, France", "5"" screen". When splitting, a comma inside double quotes is part of the value. To join values exactly as typed, turn off the switch for double quotes under More Options.
Q4. How Do I Split a Comma Separated List Into Lines?
To split a comma separated list into lines, pick Commas to Lines and paste the list. Each value is on its own line, spaces after the commas are removed, and values in quotes are kept whole, so apples, "pears, ripe", plums,, figs gives 4 lines. Pick the separator the list uses under Separator.
Q5. Can I Remove Duplicates and Sort the List?
You can remove duplicates and sort the list with two settings under More Options. With Remove duplicates on, the first copy of each value is kept and exact repeats are dropped, capitals included, and Order has A to Z, Z to A and the pasted order reversed. In A to Z order, capitals and accents do not count and digits are compared as numbers, so 2 comes before 10.
Q6. Can I Use a Semicolon, Pipe or Tab Instead of a Comma?
You can use a semicolon, a pipe or a tab instead of a comma by picking it under Separator. The list also has a comma with or without a space, a semicolon with a space and a plain space, and with Custom you can type any separator of up to 20 characters. A tab is the one to pick for values that should paste into cells side by side in a spreadsheet.
Sources
RFC 4180, Common Format and MIME Type for Comma-Separated Values (CSV) Files (IETF, October 2005), for quoting fields that contain commas or double quotes. PostgreSQL documentation, Lexical Structure, for a single quote written twice inside an SQL string constant. Microsoft Support, TEXTJOIN function, for the Excel syntax, the 32,767 character limit and the Excel versions.