Lists and text · Worked example
Preserve commas inside names when turning a list into rows
Use a four-person example to separate records from fields, preserve Lee, Morgan as one name, and check the prepared rows against the source.
A comma can separate two people in a list. It can also belong inside one person’s name. Before turning a list into rows, decide which job each comma is doing.
In this illustrative example, four volunteers each have one duty. The aim is four rows, with the name and duty kept in separate fields. We are preparing a small list by hand, not converting an unknown file format.
Start with the intended records
Here is the source:
Asha Patel | Reception, "Lee, Morgan" | Bookings, Sam Okafor | Equipment, Noor Ali | Refreshments
Each person-and-duty pair is one record. Within each record, the vertical bar, |, separates two fields: name and duty. Commas separate the records, except for the comma inside Lee, Morgan. The quotation marks around that name indicate that it belongs together; in this example, those surrounding marks are not part of the name.
That gives us four intended records:
- Asha Patel, assigned to Reception.
- Lee, Morgan, assigned to Bookings.
- Sam Okafor, assigned to Equipment.
- Noor Ali, assigned to Refreshments.
Keep the source beside the working copy. If you cannot confidently identify the intended records, ask whoever supplied the list before changing its layout. Punctuation alone cannot settle an ambiguous entry.
Why “split at every comma” fails
The source contains four commas: three record separators and one comma inside a name. Splitting at every comma therefore produces five pieces, shown here on separate lines with surrounding spaces removed:
Asha Patel | Reception
"Lee
Morgan" | Bookings
Sam Okafor | Equipment
Noor Ali | Refreshments
The second intended record has become two pieces. One contains only the beginning of the name; the other attaches the rest of the name to Bookings. The quotation marks remain visible, but they have not protected anything from a rule that splits at every comma.
The problem is not just an extra row. The relationship between the complete name and its duty has been damaged. Deleting the comma from the name would avoid that particular split, but it would also change the source text. Preserve the name and change the preparation rule instead.
Use a clear row-and-field rule
For this small example, use the following manual preparation rule:
- Put one complete record on each nonblank line. A line break ends a row.
- Within each row, use exactly one vertical bar to separate the name from the duty:
name | duty. - Treat every comma in the prepared rows as part of the field text, never as a row or field separator.
- Remove the surrounding quotation marks from
"Lee, Morgan", because we have established that they are markers, not name characters. - Use one space on each side of the vertical bar for readability. Those separator spaces are not part of either field; preserve spaces within names and duties.
This rule reserves line breaks for rows and the vertical bar for fields. Neither field may itself contain a line break or vertical bar. Check that condition before using it; all four records here meet it.
The prepared result is:
Asha Patel | Reception
Lee, Morgan | Bookings
Sam Okafor | Equipment
Noor Ali | Refreshments
There is no header row in this block. There are also no separator commas left between records: line breaks now do that job. The comma within Lee, Morgan stays exactly where it belongs.
Check both the count and a mapping
First, count the nonblank output lines: four rows, matching the four intended source records. Each row contains one vertical bar, giving two fields per row.
Then trace the vulnerable record:
- Original record:
"Lee, Morgan" | Bookings - Output row:
Lee, Morgan | Bookings - Name field:
Lee, Morgan - Duty field:
Bookings
The complete name still maps to the same duty. The marker quotes have been removed, and the following record-separator comma has been replaced by a line break.
A correct count alone cannot prove every entry survived unchanged. Compare the remaining names and duties with the source too, looking for missing records, duplicates and accidental edits.
Know where this method stops
If a field contains a vertical bar or a line break, this particular rule is unsuitable without another agreed way to represent it. Do not quietly delete those characters.
This is a bounded preparation method, not a CSV converter. If another application needs a particular import format, follow its requirements and check the imported rows separately. The useful principle remains: define record boundaries and field boundaries without sacrificing punctuation that belongs to the content.