BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TParser
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Lee Gobroski
Guest





PostPosted: Sat Mar 26, 2005 11:48 am    Post subject: TParser Reply with quote



Hello,

While searching on the web, I found reference to the TParse class. can any
one shed any more light on how to use it... like a real example...

I have found this.

http://bdn.borland.com/article/0,1410,26380,00.html
I have compiled and played with the example they use, but that did not help
a whole lot.


Thanks in advance.

Lee


Back to top
Dennis Jones
Guest





PostPosted: Sat Mar 26, 2005 7:47 pm    Post subject: Re: TParser Reply with quote




"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote

Quote:
Hello,

While searching on the web, I found reference to the TParse class. can
any
one shed any more light on how to use it... like a real example...

I have found this.

http://bdn.borland.com/article/0,1410,26380,00.html
I have compiled and played with the example they use, but that did not
help
a whole lot.

What do you want to do? There is a tokenizer class in boost (version 1.32)
that I just recently started using, and I really like it.

- Dennis



Back to top
Lee Gobroski
Guest





PostPosted: Sat Mar 26, 2005 8:14 pm    Post subject: Re: TParser Reply with quote



Dennis,

I have a CSV file that has 1500+ lines that I would like to go through and
add all values to an array. then I would like the values to show up on a
form..

an example of the file is this:
Last,First,Middle,Suffix,City
Abel,Evan,F,,Spokane
Aberle,Nicholas,Richard,,Yakima
Abigania,Melanie,M,,Everett
Abundiz,Clementina,,,Yakima
Acheson,LynnMarie,L,,Everett
Ackerlund,Kaylene,Michelle,,Ellensburg
Adamson,Kristen,E,,Ellensburg

Last,First,Middle,Suffix, AND City are all the elements of the array.

Thanks.

Lee


"Dennis Jones" <nospam (AT) bogus (DOT) com> wrote

Quote:

"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote in message
news:42454be7$1 (AT) newsgroups (DOT) borland.com...
Hello,

While searching on the web, I found reference to the TParse class. can
any
one shed any more light on how to use it... like a real example...

I have found this.

http://bdn.borland.com/article/0,1410,26380,00.html
I have compiled and played with the example they use, but that did not
help
a whole lot.

What do you want to do? There is a tokenizer class in boost (version
1.32)
that I just recently started using, and I really like it.

- Dennis





Back to top
Michel Leunen
Guest





PostPosted: Sat Mar 26, 2005 8:21 pm    Post subject: Re: TParser Reply with quote

Lee Gobroski wrote:

Quote:
While searching on the web, I found reference to the TParse class. can any
one shed any more light on how to use it... like a real example...

I have writen a little tip article about the TParser class but you have
to know that it's just a curiosity, quite unusable. Just play with it
and you'll understand what I mean.
http://www.leunen.com/cbuilder/tparser.html

Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------

Back to top
Dennis Jones
Guest





PostPosted: Sat Mar 26, 2005 9:11 pm    Post subject: Re: TParser Reply with quote


"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote

Quote:
Dennis,

I have a CSV file that has 1500+ lines that I would like to go through and
add all values to an array. then I would like the values to show up on a
form..

an example of the file is this:
Last,First,Middle,Suffix,City
Abel,Evan,F,,Spokane
Aberle,Nicholas,Richard,,Yakima
Abigania,Melanie,M,,Everett
Abundiz,Clementina,,,Yakima
Acheson,LynnMarie,L,,Everett
Ackerlund,Kaylene,Michelle,,Ellensburg
Adamson,Kristen,E,,Ellensburg

Last,First,Middle,Suffix, AND City are all the elements of the array.


The tokenizer template in boost would definitely work. You could do this
very easily with two tokenizers: one to iterate through the lines (using
carriage return as the delimiter), and one to iterate through the elements
in each line (using comma as the delimiter).

On the other hand, if you are looking for a simple VCL implementation (as
opposed to boost), you could do this too: Load the file into a TStringList,
then assign each string (line) to the CommaText property of a second
TStringList to parse the values from the line. Something like this
(untested):

TStringList *pFile = new TStringList;
// after this line executes, each string in 'pFile' will be one line of the
file
pFile->LoadFromFile( "myfile.txt" );

TStringList *pLine = new TStringList;
for ( int i=0; i<pFile->Count; ++i )
{
// after this line executes, each string in 'pLine' will be one value
from the CSV line
pLine->CommaText = pFile->Strings[i];
}

LoadFromFile() does all the work of splitting the file into separate lines,
and the CommaText property does all the work of parsing the values out of a
CSV string.

Good luck,

- Dennis



Back to top
Lee Gobroski
Guest





PostPosted: Mon Mar 28, 2005 1:01 am    Post subject: Re: TParser Reply with quote

Dennis,

Thanks so much. I can now get each string and what not. Now I am wondering
how I would go about dividing the text up. You see I want the first name,
last name, and city all in text boxes. Then I want to click on next and
have it move to the next record.

I hope that is clear on what I want.

Thanks again,

Lee


"Dennis Jones" <nospam (AT) bogus (DOT) com> wrote

Quote:

"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote in message
news:4245c2b8$1 (AT) newsgroups (DOT) borland.com...
Dennis,

I have a CSV file that has 1500+ lines that I would like to go through
and
add all values to an array. then I would like the values to show up on a
form..

an example of the file is this:
Last,First,Middle,Suffix,City
Abel,Evan,F,,Spokane
Aberle,Nicholas,Richard,,Yakima
Abigania,Melanie,M,,Everett
Abundiz,Clementina,,,Yakima
Acheson,LynnMarie,L,,Everett
Ackerlund,Kaylene,Michelle,,Ellensburg
Adamson,Kristen,E,,Ellensburg

Last,First,Middle,Suffix, AND City are all the elements of the array.


The tokenizer template in boost would definitely work. You could do this
very easily with two tokenizers: one to iterate through the lines (using
carriage return as the delimiter), and one to iterate through the elements
in each line (using comma as the delimiter).

On the other hand, if you are looking for a simple VCL implementation (as
opposed to boost), you could do this too: Load the file into a
TStringList,
then assign each string (line) to the CommaText property of a second
TStringList to parse the values from the line. Something like this
(untested):

TStringList *pFile = new TStringList;
// after this line executes, each string in 'pFile' will be one line of
the
file
pFile->LoadFromFile( "myfile.txt" );

TStringList *pLine = new TStringList;
for ( int i=0; i<pFile->Count; ++i )
{
// after this line executes, each string in 'pLine' will be one value
from the CSV line
pLine->CommaText = pFile->Strings[i];
}

LoadFromFile() does all the work of splitting the file into separate
lines,
and the CommaText property does all the work of parsing the values out of
a
CSV string.

Good luck,

- Dennis





Back to top
Lee Gobroski
Guest





PostPosted: Mon Mar 28, 2005 2:03 am    Post subject: Re: TParser Reply with quote

here is what I have now...

String list[4]; //4 element array
String name; //file name
TStringList *pFile = new TStringList;
TStringList *pLine = new TStringList;

if(Form1->OpenDialog1->Execute())
{
name = Form1->OpenDialog1->FileName;
}
pFile->LoadFromFile(name);

for ( int i=0; i<pFile->Count; ++i )
{
// after this line executes, each string in 'pLine' will be one value
from the CSV line
pLine->CommaText = pFile->Strings[i];
}

list[0] = pLine->CommaText.SubString(0,6);

edtLastName->Text = pLine->CommaText.SubString(0,6); //this works, just not
dynamic

"Dennis Jones" <nospam (AT) bogus (DOT) com> wrote

Quote:

"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote in message
news:4245c2b8$1 (AT) newsgroups (DOT) borland.com...
Dennis,

I have a CSV file that has 1500+ lines that I would like to go through
and
add all values to an array. then I would like the values to show up on a
form..

an example of the file is this:
Last,First,Middle,Suffix,City
Abel,Evan,F,,Spokane
Aberle,Nicholas,Richard,,Yakima
Abigania,Melanie,M,,Everett
Abundiz,Clementina,,,Yakima
Acheson,LynnMarie,L,,Everett
Ackerlund,Kaylene,Michelle,,Ellensburg
Adamson,Kristen,E,,Ellensburg

Last,First,Middle,Suffix, AND City are all the elements of the array.


The tokenizer template in boost would definitely work. You could do this
very easily with two tokenizers: one to iterate through the lines (using
carriage return as the delimiter), and one to iterate through the elements
in each line (using comma as the delimiter).

On the other hand, if you are looking for a simple VCL implementation (as
opposed to boost), you could do this too: Load the file into a
TStringList,
then assign each string (line) to the CommaText property of a second
TStringList to parse the values from the line. Something like this
(untested):

TStringList *pFile = new TStringList;
// after this line executes, each string in 'pFile' will be one line of
the
file
pFile->LoadFromFile( "myfile.txt" );

TStringList *pLine = new TStringList;
for ( int i=0; i<pFile->Count; ++i )
{
// after this line executes, each string in 'pLine' will be one value
from the CSV line
pLine->CommaText = pFile->Strings[i];
}

LoadFromFile() does all the work of splitting the file into separate
lines,
and the CommaText property does all the work of parsing the values out of
a
CSV string.

Good luck,

- Dennis





Back to top
Dennis Jones
Guest





PostPosted: Mon Mar 28, 2005 2:14 am    Post subject: Re: TParser Reply with quote


"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote

Quote:
here is what I have now...

String list[4]; //4 element array
String name; //file name
TStringList *pFile = new TStringList;
TStringList *pLine = new TStringList;

if(Form1->OpenDialog1->Execute())
{
name = Form1->OpenDialog1->FileName;
}
pFile->LoadFromFile(name);

for ( int i=0; i<pFile->Count; ++i )
{
// after this line executes, each string in 'pLine' will be one value
from the CSV line
pLine->CommaText = pFile->Strings[i];
}

list[0] = pLine->CommaText.SubString(0,6);

edtLastName->Text = pLine->CommaText.SubString(0,6); //this works, just
not
dynamic

Lee:

You missed the most important part of my message! The CommaText property
does ALL the work for you. After CommaText is assigned the an entire line,
you can then reference each element of the line via the Strings[] property
(hence my comment about each string in pLine)...there is no need to parse it
manually with SubString(). For example:

// after this line executes, each string in 'pLine' will be one value from
the CSV line
pLine->CommaText = pFile->Strings[i];

// now get each element and put it in an edit box:
edtLastName->Text = pLine->Strings[0];
edtFirstName->Text = pLine->Strings[1];
edtMiddleName->Text = pLine->Strings[2];
edtSuffix->Text = pLine->Strings[3];
etc...

- Dennis



Back to top
Lee Gobroski
Guest





PostPosted: Mon Mar 28, 2005 4:11 am    Post subject: Re: TParser Reply with quote

Dennis,

I guess that is what happens when you read things while suffering sleep
deprivation!!!

you are right I missed that, I'll let you know.

Thanks so much

Lee

"Dennis Jones" <nospam (AT) bogus (DOT) com> wrote

Quote:

"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote in message
news:424765f8$1 (AT) newsgroups (DOT) borland.com...
here is what I have now...

String list[4]; //4 element array
String name; //file name
TStringList *pFile = new TStringList;
TStringList *pLine = new TStringList;

if(Form1->OpenDialog1->Execute())
{
name = Form1->OpenDialog1->FileName;
}
pFile->LoadFromFile(name);

for ( int i=0; i<pFile->Count; ++i )
{
// after this line executes, each string in 'pLine' will be one value
from the CSV line
pLine->CommaText = pFile->Strings[i];
}

list[0] = pLine->CommaText.SubString(0,6);

edtLastName->Text = pLine->CommaText.SubString(0,6); //this works, just
not
dynamic

Lee:

You missed the most important part of my message! The CommaText property
does ALL the work for you. After CommaText is assigned the an entire
line,
you can then reference each element of the line via the Strings[] property
(hence my comment about each string in pLine)...there is no need to parse
it
manually with SubString(). For example:

// after this line executes, each string in 'pLine' will be one value from
the CSV line
pLine->CommaText = pFile->Strings[i];

// now get each element and put it in an edit box:
edtLastName->Text = pLine->Strings[0];
edtFirstName->Text = pLine->Strings[1];
edtMiddleName->Text = pLine->Strings[2];
edtSuffix->Text = pLine->Strings[3];
etc...

- Dennis





Back to top
Dennis Jones
Guest





PostPosted: Mon Mar 28, 2005 4:30 am    Post subject: Re: TParser Reply with quote


"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote

Quote:
Dennis,

I guess that is what happens when you read things while suffering sleep
deprivation!!!

you are right I missed that, I'll let you know.

Thanks so much

Lee

My pleasure.

Happy Easter,

- Dennis



Back to top
Lee Gobroski
Guest





PostPosted: Mon Mar 28, 2005 6:06 am    Post subject: Re: TParser Reply with quote

Dennis,

I hate to be a bother to you... but I have one more question for you. How
can I access the first element of the string list. I looked up on the help,
and there does not appear to be a way.

Thanks for all your help so far.

Lee


"Dennis Jones" <nospam (AT) bogus (DOT) com> wrote

Quote:

"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote in message
news:424783f3 (AT) newsgroups (DOT) borland.com...
Dennis,

I guess that is what happens when you read things while suffering sleep
deprivation!!!

you are right I missed that, I'll let you know.

Thanks so much

Lee

My pleasure.

Happy Easter,

- Dennis





Back to top
Lee Gobroski
Guest





PostPosted: Mon Mar 28, 2005 6:54 am    Post subject: Re: TParser Reply with quote

Dennis,

This is what I have done to solve that issue of changing values in teh edit
boxes:


TStringList *pFile = new TStringList; //entire file stringlist
TStringList *pLine = new TStringList; //single line stringlist
String name; //file name
int recNum = 0;

void refillEditBoxes(int dispRecNums)
{
pFile->LoadFromFile(name);
if (dispRecNums == 0)
{
recNum = pFile->Count - 1;
}
if (dispRecNums >= pFile->Count - 1)
{
recNum = 1;
}

pLine->CommaText = pFile->Strings[recNum];
Form1->edtLastName->Text = pLine->Strings[0];
Form1->edtFirstName->Text = pLine->Strings[1];
Form1->edtMiddleName->Text = pLine->Strings[2];
Form1->edtCity->Text = pLine->Strings[4];
}

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnOpenClick(TObject *Sender)
{

if(Form1->OpenDialog1->Execute())
{
name = Form1->OpenDialog1->FileName;
}
pFile->LoadFromFile(name);

for ( int i=0; i<pFile->Count; ++i )
{
// after this line executes, each string in 'pLine' will be one value
from the CSV line
pLine->CommaText = pFile->Strings[i];
}
recNum = pFile->Count;
edtLastName->Text = pLine->Strings[0];
edtFirstName->Text = pLine->Strings[1];
edtMiddleName->Text = pLine->Strings[2];
edtCity->Text = pLine->Strings[4];

}
//---------------------------------------------------------------------------
void __fastcall TForm1::NextClick(TObject *Sender)
{
recNum++;
refillEditBoxes(recNum);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PreviousClick(TObject *Sender)
{
recNum--;
refillEditBoxes(recNum);
}
//---------------------------------------------------------------------------


Do you know of any other way to do that...???


"Dennis Jones" <nospam (AT) bogus (DOT) com> wrote

Quote:

"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote in message
news:424783f3 (AT) newsgroups (DOT) borland.com...
Dennis,

I guess that is what happens when you read things while suffering sleep
deprivation!!!

you are right I missed that, I'll let you know.

Thanks so much

Lee

My pleasure.

Happy Easter,

- Dennis





Back to top
Dennis Jones
Guest





PostPosted: Mon Mar 28, 2005 7:58 pm    Post subject: Re: TParser Reply with quote


"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote

Quote:
Dennis,

I hate to be a bother to you... but I have one more question for you. How
can I access the first element of the string list. I looked up on the
help,
and there does not appear to be a way.

The first element is index 0.

- Dennis



Back to top
Dennis Jones
Guest





PostPosted: Mon Mar 28, 2005 8:00 pm    Post subject: Re: TParser Reply with quote


"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote

Quote:
Dennis,

This is what I have done to solve that issue of changing values in teh
edit
boxes:

<code sipped>

Quote:
Do you know of any other way to do that...???

Sorry, but I don't quite understand what you are asking.

- Dennis



Back to top
Lee Gobroski
Guest





PostPosted: Tue Mar 29, 2005 1:31 am    Post subject: Re: TParser Reply with quote

Dennis,

I really was not asking anything that time... LOL Hard to believe I know.
I understand the first element is index 0,

recNum = 0
pLine->CommaText = pFile->Strings[recNum];

The only issue I have with this solution, and I don't know if it can be
avoided, is that I need to call on the file every time I want to change the
values. can I load the whole file in to memory, and then access it like an
array...

Thanks

Lee


"Dennis Jones" <nospam (AT) bogus (DOT) com> wrote

Quote:

"Lee Gobroski" <gobroski (AT) oddlee (DOT) net> wrote in message
news:4247aa05$1 (AT) newsgroups (DOT) borland.com...
Dennis,

This is what I have done to solve that issue of changing values in teh
edit
boxes:

code sipped

Do you know of any other way to do that...???

Sorry, but I don't quite understand what you are asking.

- Dennis





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.