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 

Parsing strings, sometimes hard

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Steven
Guest





PostPosted: Fri Feb 17, 2006 7:03 pm    Post subject: Parsing strings, sometimes hard Reply with quote



I am trying to parse this string on a webpage, I want to
retrieve the version number of some software. When
I parse, I am not getting the correct info. back. I really
don't want to be adding in "+1 or +3 etc" to the code.

Is there a more efficient way of scraping the information
when going through the stringlist() to get what I want?

// .h
#define START "var curversion = '"
#define END "';"

//info in stringlist
var curversion = '2.0.5.6316';

//aVal in debugger
/t/t/t/t/tvar curversion = '2.0.5.6316';

//code
AnsiString pVal = pList->Strings[i];
int cnt = sizeof(START); //cnt returns 19
aVal.Delete(1, cnt);
Pos = aVal.Pos(ZIPBACKUP_END);
if(Pos > 0)
aVal.Delete(Pos, aVal.Length());

// return result
= '2.0.5.6316

Somehow adding in the tabs to the string does not return a found
string: #define START "/t/t/t/t/tvar curversion = '2.0.5.6316';"
I could always do a +4 to remove the rest of the info, but, is there
a better way?


Appreciate it

Steven
Back to top
Steven
Guest





PostPosted: Fri Feb 17, 2006 9:03 pm    Post subject: Re: Parsing strings, sometimes hard Reply with quote



Quote:
Have you taken a look at tools like boost::regex
or the pcre lib? They can be very useful in such
cases.

Actually I didn't think about using any outside libs
for parsing, apart from what funcs that come with
bds2006. Plus, with something as simple as parsing
a few webpages, I don't think I will need anything
that complex.


Steven
Back to top
Giuliano
Guest





PostPosted: Fri Feb 17, 2006 9:03 pm    Post subject: Re: Parsing strings, sometimes hard Reply with quote



On Fri, 17 Feb 2006 14:15:18 -0600, "Steven" <stef (AT) bondo (DOT) edu> wrote:

Quote:
a few webpages, I don't think I will need anything
that complex.

IMHO, REs are simpler to use (and often faster), respect to write hand crafted
code.

Regards

Giuliano
Back to top
Steven
Guest





PostPosted: Fri Feb 17, 2006 9:03 pm    Post subject: Re: Parsing strings, sometimes hard Reply with quote

Quote:
IMHO, REs are simpler to use (and often faster), respect to write hand
crafted
code.


Where in the world do you find those libraries anyway?
Back to top
Giuliano
Guest





PostPosted: Fri Feb 17, 2006 9:03 pm    Post subject: Re: Parsing strings, sometimes hard Reply with quote

On Fri, 17 Feb 2006 12:08:35 -0600, "Steven" <stef (AT) bondo (DOT) edu> wrote:

[snip]
Quote:
but, is there
a better way?

Hi Steven,

generally speaking, in the most cases,
best results can be obtained using regular
expressions, at least - directly - for non
recursive structures. Parsing using RE engines,
can be pretty simple, fast and straightforward.

Have you taken a look at tools like boost::regex
or the pcre lib? They can be very useful in such
cases.

Regards

Giuliano
Back to top
Hans Galema
Guest





PostPosted: Fri Feb 17, 2006 11:03 pm    Post subject: Re: Parsing strings, sometimes hard Reply with quote

Steven wrote:
Quote:
I am trying to parse this string on a webpage,

Do you want to extract "2.0.5.6316" from a line "var curversion = '2.0.5.6316';" ?

AnsiString Line = " var curversion = '2.0.5.6316';";

#define START "var curversion = '"
#define END "';"

int pos1 = Line.Pos ( START );
int pos2 = Line.Pos ( END );

if ( pos1 && pos2 && pos2 > pos1 )
{
pos1 += strlen(START);

AnsiString Result = Line.SubString ( pos1, pos2 - pos1 );

ShowMessage ( Result );
}

Hans.
Back to top
Chris Uzdavinis (TeamB)
Guest





PostPosted: Fri Feb 17, 2006 11:03 pm    Post subject: Re: Parsing strings, sometimes hard Reply with quote

"Steven" <stef (AT) bondo (DOT) edu> writes:

Quote:
IMHO, REs are simpler to use (and often faster), respect to write hand
crafted
code.


Where in the world do you find those libraries anyway?

Check out boost. (www.boost.org)

--
Chris (TeamB);
Back to top
Steven
Guest





PostPosted: Sat Feb 18, 2006 12:03 am    Post subject: Re: Parsing strings, sometimes hard Reply with quote

Thanks Hans

"Hans Galema" <notused (AT) notused (DOT) nl> wrote in message
news:43f6526f$1 (AT) newsgroups (DOT) borland.com...
Quote:
Steven wrote:
I am trying to parse this string on a webpage,

Do you want to extract "2.0.5.6316" from a line "var curversion =
'2.0.5.6316';" ?

AnsiString Line = " var curversion = '2.0.5.6316';";
Back to top
Steven
Guest





PostPosted: Sat Feb 18, 2006 12:03 am    Post subject: Re: Parsing strings, sometimes hard Reply with quote

Thanks for the link Chris.

"Chris Uzdavinis (TeamB)" <chris (AT) uzdavinis (DOT) com> wrote in message
news:j5hd6xr6kj.fsf (AT) explicit (DOT) atdesk.com...
Quote:
"Steven" <stef (AT) bondo (DOT) edu> writes:

Check out boost. (www.boost.org)

--
Chris (TeamB);
Back to top
Giuliano
Guest





PostPosted: Sun Feb 19, 2006 12:03 pm    Post subject: Re: Parsing strings, sometimes hard Reply with quote

On Fri, 17 Feb 2006 14:43:44 -0600, "Steven" <stef (AT) bondo (DOT) edu> wrote:

Quote:
IMHO, REs are simpler to use (and often faster), respect to write hand
crafted
code.


Where in the world do you find those libraries anyway?


Hi,

other than boost (Chris gave you the link),
you can try to use PCRE which comes with BCB.
If you need a sample project for BCB6 let me
know: I will send to you a zip.

Ciao

Giuliano
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
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.