Does anyone know an easy way to read comma delimited data "properly".
That is, knowing that fields are delimited by commas, but to ignore
commas that are inside quotes surrounding a field... BUT, I can't just
scan for quotes as part of the delimiter because number fields will have
no quotes.
So a typical record will look like the following:
0124,"Chris","Dog, Cat",78,"Macintosh","27-44157"
note that the number only fields have no quotes, but a number MIGHT be
inside quotes if it is being treated as text. And inside some quotes can
be a comma.
I had been doing this by reading the data as a TextInputStream. Read a
record using ReadLine, then use NthField with a comma as a seperator, and
then use ReplaceAll to strip any quotes.
The snag I have hit is fields that have a comma as part of the text in
the field are being picked up as a field break by NthField.
Does anyone know of a way to do this right? Or does anyone have working
code they want to share (maybe reading it as a binary file and walking
thru looking for commas and quotes).
If no one already has such, I guess I will have to write a method to read
it as a binary file, but I am hoping someone knows an easy way to do it
as text, or has already done the work and wishes to share.
TIA
-chris
<http://www.mythtech.net>
|