realbasic-nug
[Top] [All Lists]

Re: Reading comma delimited data

To: REALbasic Network Users Group <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Reading comma delimited data
From: Hasan Edain <hed at slumberland dot org>
Date: Fri, 30 Aug 2002 09:53:47 -0700
So I didn't see any mention of use of regEx to solve this problem.

if you use a regEx, then you can keep your same code structure. "? will find 0 or one ". If you need a clearer example let me know.

On Thursday, August 29, 2002, at 03:37 PM, chris wrote:

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>


---
Subscribe to the digest:
<mailto:realbasic-nug-digest at lists dot realsoftware dot com>
Unsubscribe:
<mailto:realbasic-nug-off at lists dot realsoftware dot com>


Hasan Edain
hed at slumberland dot org
"Minds are like parachutes, they only function when open"



<Prev in Thread] Current Thread [Next in Thread>