You are here:  » CSV with occasional quotes


CSV with occasional quotes

Submitted by CultOfBlah on Thu, 2007-11-08 18:01 in

Hi,

I have a csv file where one field within it has quotes around the field (because within the data of that field there's commas - example below). MagicParser is splitting the field on the comma and making the quote part of that field's data.

example data:
This Venue,"This Street, Glasgow, Lanarkshire",Glasgow,G1 2AB,Another field,Yet another field

MagicParser returns the fields as:-
field1 = This Venue
field2 = "This Street
field3 = Glasgow
field4 = Lanarkshire"
field5 = Glasgow
field6 = G1 2AB
field7 = Another field
field8 = Yet another field

Is there any way for MagicParser to properly deal with this, so that it treats everything within the quotes as one field?

(Other than this issue it's a great product, saving me hours and hours of work! - thanks).

Submitted by support on Thu, 2007-11-08 18:05

Hi,

Thanks for your comments.

This behavior is consistent with auto-detection, as there is no quote character at the beginning of the line it is not picked up.

However, if you specify a Format String for your feed, indicate Quote separated values, Magic Parser only goes into the quoted state if a quote appears immediately after the separator character, so it should work with your data.

If your feed is comma separated, quoted text, with no header row, try the following format string as the 3rd parameter to MagicParser_parse()...

csv|44|0|34

Hope this helps,
Cheers,
David.

Submitted by CultOfBlah on Thu, 2007-11-08 18:21

That's sorted it, cheers. :-)