Skip to content

question about escaping #50

@ghost

Description

Question

With the default config, how can I escape commas and line returns within a field in order to ensure the resulting CSV is readable?

Additional Context

I'm hacking together an app with Swift and Xcode and I'm a complete novice. To provide the app with some basic data I have provided it with csv files, which are parsed with CodableCSV. Many thanks for the package!

Using basic data it's working fine. I have tried not to fiddle with the configuration. Delimiters are commas and end of line is "\r".

However, for one of my tables I need now to expand one of the fields to include sentences or even paragraphs of text, which contain commas and newlines. Initially I understood from the documentation that the way to do this is to enclose the whole field in double quotes ("..."). That crashed the app and so did escaping the individual offending characters with double quotes (",) or with a backslash (,).

Many thanks for any pointers!

Example extract of table:

id,title,introduction
reg,Regular Models,"The good news for learners of Spanish..."
irr_i,Essentials I,
irr_ii,Essentials II,

Error message:

CodableCSV/Reader.swift:75:` Fatal error: 'try!' expression unexpectedly raised an error: [CSVReader] Invalid input
	Reason: The targeted field parsed successfully. However, the character right after it was not a field nor row delimiter.
	Help: If your CSV is CRLF, change the row delimiter to "\r\n" or add a trim strategy for "\r".
	User info: Row index: 1, Field: The good news for learners of `Spanish...

System

  • OS: macOS 12.3
  • CodableCSV: 0.6.7
  • Xcode 13

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions