Why does a delimiter inside a field split a text record unexpectedly?
Quick answer
A delimiter-based parser uses a character such as a comma to mark where one field ends and the next begins. If that character also appears inside a value, the parser may split the value unless the format’s rules mark it as part of the field. In CSV, a comma-containing value can be enclosed in quotes, but quoting and escaping rules vary between formats and parsers.
The question, the details, the next step.
A practical checklist
Write down the intended fields and their order before editing the record.
Identify the delimiter used by the file and the parser that reads it.
Check that parser’s rules for delimiters inside fields and for quotes inside quoted fields.
Represent the delimiter-containing value using the format’s supported quoting or escaping convention.
Test a small sample and compare the parsed field count and values with what you intended.
A few more useful answers
Does adding quotes always protect a delimiter inside a field?
Only when the format and parser recognize those quotes as field quoting. Check the specific parser’s rules; the CSV example does not establish behavior for every delimited-text format.
What if the field itself contains a quote character?
Use the escaping rule supported by the format and parser. Quotes inside quoted CSV fields need escaping, but the exact method is not universal. [S1]
Why not just split the record at every comma?
That approach cannot distinguish a comma separating fields from a comma that belongs inside a value. A format-aware parser can apply the format’s rules for quoted fields.
Sources
References used for this guide.
- [S1] Parsing CSV Files in UWP Apps - Microsoft Developer Magazine learn.microsoft.com · Checked
