Board index » cppbuilder » seeking in an AnsiString

seeking in an AnsiString


2005-07-08 01:27:16 AM
cppbuilder45
Hello,
I want to seek in an AnsiString?!?
e.g.:
In the AnsiString 'ExampleString' is the following text:
"Parameters ... ASW1=5.987, PQA=6.431, ASW3=9.777"
I want to search in this line for the string 'PQA=' and
write the number '6.431' into an double 'dPQA'.
Thank you and greetings ...
Frank ;)
 
 

Re:seeking in an AnsiString

"Frank" < XXXX@XXXXX.COM >wrote in message
Quote
Hello,

I want to seek in an AnsiString?!?

e.g.:
In the AnsiString 'ExampleString' is the following text:
"Parameters ... ASW1=5.987, PQA=6.431, ASW3=9.777"

I want to search in this line for the string 'PQA=' and
write the number '6.431' into an double 'dPQA'.
Use AnsiString's member function Pos. Like this:
double dPQA = 0;
int P = ExampleString.Pos( "PQA=" );
if( P>0 ) // Because AnsiString is 1 based, so 0 means nothing found.
{
// This searches from the PQA= onwards, until it finds the ,
int E = ExampleString.SubString( P + 4, ExampleString.Length() ).Pos(
"," );
if( E>0 )
{
try
{
dPQA = ExampleString.SubString( P+4, E - 1 ).ToDouble();
}
catch( const EConvertError &E )
{
dPQA = 0;
}
}
}
HTH
Jonathan
 

Re:seeking in an AnsiString

This looks good! :)
Thank you ...
Jonathan Benedicto schrieb:
Quote
"Frank" < XXXX@XXXXX.COM >wrote in message
news:42cd65e0$ XXXX@XXXXX.COM ...

>Hello,
>
>I want to seek in an AnsiString?!?
>
>e.g.:
>In the AnsiString 'ExampleString' is the following text:
>"Parameters ... ASW1=5.987, PQA=6.431, ASW3=9.777"
>
>I want to search in this line for the string 'PQA=' and
>write the number '6.431' into an double 'dPQA'.


Use AnsiString's member function Pos. Like this:

double dPQA = 0;
int P = ExampleString.Pos( "PQA=" );
if( P>0 ) // Because AnsiString is 1 based, so 0 means nothing found.
{
// This searches from the PQA= onwards, until it finds the ,
int E = ExampleString.SubString( P + 4, ExampleString.Length() ).Pos(
"," );
if( E>0 )
{
try
{
dPQA = ExampleString.SubString( P+4, E - 1 ).ToDouble();
}
catch( const EConvertError &E )
{
dPQA = 0;
}
}
}

HTH

Jonathan


 

{smallsort}

Re:seeking in an AnsiString

"Jonathan Benedicto" < XXXX@XXXXX.COM >wrote in message
Quote
Use AnsiString's member function Pos. Like this:
Alternatively:
double dPQA;
AnsiString s;
char *start = AnsiStrPos(ExampleString.c_str(), "PQA=");
if( start )
{
start += 4;
char *end = AnsiStrScan(start, ',');
if( end )
s = AnsiString(start, end-start);
else
s = start;
}
try {
dPQA = s.ToDouble();
}
catch(const Exception &) {
dPQA = 0.0;
}
Alternatively:
TStringList *Params = new TStringList;
try
{
Params->CommaText = "ASW1=5.987, PQA=6.431, ASW3=9.777";
try {
dPQA = Params->Values["PQA"].ToDouble();
}
catch(const Exception &) {
dPQA = 0.0;
}
}
__finally {
delete Params;
}
Gambit
 

Re:seeking in an AnsiString

On Thu, 07 Jul 2005 19:27:16 +0200, Frank wrote:
Quote
I want to seek in an AnsiString?!?
check AnsiPos in the help
--
Good luck,
liz