Board index » cppbuilder » Parsing a CSV file...

Parsing a CSV file...


2005-03-24 07:58:23 PM
cppbuilder26
Hello all,
I have been spending the last couple of days trying to find a way I can load
a CSV file, and then parse it. what I would like top do ideally is load the
first record of the file in to the form, and then click on next and then
have it show the next record. I was wondering if that could be done with
out leaving the file open, of having to reopen it, or look at the file.
thanks in advance for your help.
Lee
 
 

Re:Parsing a CSV file...

Recently I was messing aroung with CSV files and wrote import / export
routines for such formats so I think I might help you
but didn't quite get what are you trying to accomplish. As far as I
understood you want to open the file once, close it and then
not use it any more. In that case you have to read the file's content in an
array in your program and use it later. Or you mean something else?
 

Re:Parsing a CSV file...

Lee Gobroski wrote:
Quote
I have been spending the last couple of days trying to find a way I can load
a CSV file, and then parse it. what I would like top do ideally is load the
first record of the file in to the form, and then click on next and then
have it show the next record. I was wondering if that could be done with
out leaving the file open, of having to reopen it, or look at the file.
For files certainly up to 20 MB you can load them in a TStringList with
one command.
StringList->LoadFromFile ( your filename );
I suppose that every record is on a line.
int nrecs = StringList1->Count;
To get the line for a record with a certain recnr < nrecs:
AnsiString Line = StringList->Strings[recnr];
Now you have to parse only this line but TStringList can do for
you that.
Is the ',' the separator ?
Put the line in a different TStringList with:
StringList2->CommaText = Line;
Now StringList2->Strings[] contain the values.
Hans.
 

{smallsort}

Re:Parsing a CSV file...

"Lee Gobroski" < XXXX@XXXXX.COM >writes:
Quote
I have been spending the last couple of days trying to find a way I can load
a CSV file, and then parse it. what I would like top do ideally is load the
first record of the file in to the form, and then click on next and then
have it show the next record. I was wondering if that could be done with
out leaving the file open, of having to reopen it, or look at the file.
Is there a problem with keeping the file open?
After all, it's a cheap way to prevent somebody else from writing to
it while you are parsing it.
 

Re:Parsing a CSV file...

Hello,
Thanks for you help thus far. here is a sample of what I am reading in:
Last,First,Middle,Suffix,City
Abel,Evan,F,III,Spokane
Aberle,Nicholas,Richard,,Yakima
I kind of guessed that I would have to add the file to an array, but I am
sure just exactly how to do that in C++ Builder 6.0. The current file is
only 55 K so I don't have to worry about the 20 meg limit of the
TStringList.
again thanks for your help thus far
Lee
"Lee Gobroski" < XXXX@XXXXX.COM >wrote in message
Quote
Hello all,

I have been spending the last couple of days trying to find a way I can
load a CSV file, and then parse it. what I would like top do ideally is
load the first record of the file in to the form, and then click on next
and then have it show the next record. I was wondering if that could be
done with out leaving the file open, of having to reopen it, or look at
the file.

thanks in advance for your help.

Lee

 

Re:Parsing a CSV file...

Lee Gobroski wrote:
Quote
so I don't have to worry about the 20 meg limit of the
TStringList.
TStringList has a 4 or 8 GB limit only. But first of all available memory.
I mentionend 20 MB but could as well have said 40 MB. The reason
beeing that operations would take longer and longer with increasing size.
Hans.
 

Re:Parsing a CSV file...

OK, thanks.
How do I get the file contents to the Tstinglist?
Thanks
Lee
"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
Lee Gobroski wrote:

>so I don't have to worry about the 20 meg limit of the TStringList.

TStringList has a 4 or 8 GB limit only. But first of all available memory.

I mentionend 20 MB but could as well have said 40 MB. The reason
beeing that operations would take longer and longer with increasing size.

Hans.
 

Re:Parsing a CSV file...

Lee Gobroski wrote:
Quote
How do I get the file contents to the Tstinglist?
That I already told you.
Hans.
 

Re:Parsing a CSV file...

On Thu, 24 Mar 2005 12:07:54 -0800, Lee Gobroski wrote:
Quote
How do I get the file contents to the Tstinglist?
Check the help for the LoadFromFile() method, as Hans already
suggested
--
Good luck,
liz
 

Re:Parsing a CSV file...

Hans,
Thanks. I missed that.
Lee
"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
Lee Gobroski wrote:

>How do I get the file contents to the Tstinglist?

That I already told you.

Hans.