You are here:  » Handling line breaks inside of CSV values?


Handling line breaks inside of CSV values?

Submitted by nickdesb on Thu, 2011-02-03 17:30 in

I have a CSV that was exported from Excel, and one of the values in the header row has a line break in it (created by pressing Alt+Enter within the text in the cell in Excel).

The result is that MagiParser interprets this as the end of the row, and starts reading the rest of the value and everything after it as a new row (producing gibberish output).

The beginning of the CSV looks like this (with the offending line break after "Tree , which is NOT the end of the header row...):

{code saved}

My preference would be for MagicParser to simply ignore line breaks within values (as enclosed by double-quotes). Any other ideas would be appreciated...

Submitted by support on Thu, 2011-02-03 17:45

Hi Nick,

Magic Parser is designed to handle line breaks within quoted text fields, but I notice that your data only quotes text fields if they contain a line break (and presumably another quote).

In this situation, Magic Parser won't auto-detect the quoted text, so you would need to specify the correct Format String manually in the 3rd parameter in your call to MagicParser_parse().

Looking at your example data, the format is Quoted Text, Header Row, Comma Separated, which is a Format String of csv|44|1|34 - so in your code, make sure that you are using something like:

MagicParser_parse("filename.csv","myRecordHandler,"csv|44|1|34");

That should be all it is!

Cheers,
David.
--
MagicParser.com