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 

Re: Pos and AnsiCompareIC

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





PostPosted: Tue Dec 23, 2003 2:51 am    Post subject: Re: Pos and AnsiCompareIC Reply with quote



I am not sure if this is what you want:

bool DoesSubstringExist_I(const AnsiString S, const String Substring)
{
if (S.LowerCase().Pos(Substring.LowerCase()))
return true;

return false;
}

// Call
if (DoesSubstringExist_I("Test String", "tes" ))
ShowMessage("yes");
else
ShowMessage("no");


Rodolfo

"Helena Ramos" <hcramos (AT) swbell (DOT) net> wrote

Quote:

I am trying to do a case insensitive match on a string. I cant seem to
figure out how to make it work with Pos() and AnsiCompareIC(), can someone

offer some advice please.
Quote:

AnsiString tmp = "Test String";

int MatchPos = tmp.Pos("tes");

How can you combine Pos() with AnsiCompareIC() to make it one string?


Thanks

Helena



Back to top
Rodolfo Frino - Macrosoft
Guest





PostPosted: Tue Dec 23, 2003 3:03 am    Post subject: Re: Pos and AnsiCompareIC Reply with quote



or the Multibyte version

bool DoesSubstringExist_IM(const AnsiString S, const String Substring)
{
// case insensitive and multibyte character strings version

if (S.LowerCase().AnsiPos(Substring.LowerCase()))
return true;

return false;
}

Rodolfo


Back to top
Rodolfo Frino - Macrosoft
Guest





PostPosted: Tue Dec 23, 2003 5:09 am    Post subject: Re: Pos and AnsiCompareIC Reply with quote



Or if you want the position of the substring (case insensitve)

int GetSubstringPos_I(const AnsiString S, const String Substring)
{
// case insensitive

return S.LowerCase().Pos(Substring.LowerCase());
}


int GetSubstringPos_IM(const AnsiString S, const String Substring)
{
// case insensitive and multibyte character strings version

return S.LowerCase().AnsiPos(Substring.LowerCase());
}

Rodolfo



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Dec 23, 2003 7:29 pm    Post subject: Re: Pos and AnsiCompareIC Reply with quote

"Helena Ramos" <hcramos (AT) swbell (DOT) net> wrote


Quote:
I am trying to do a case insensitive match on a string. I
cant seem to figure out how to make it work with Pos()
and AnsiCompareIC(), can someone offer some advice please.

Pos() is case sensitive, so you cannot use it for what you ask. One way to
search for a substring case-insensitively is to simply convert the entire
string to upper-case or lower-case first and then search it, ie:

AnsiString tmp = "Test String";
int MatchPos = tmp.LowerCase().Pos("tes");

The alternative is to just scan the original string manually (untested):

int __fastcall MyPos(const AnsiString &Str, const AnsiString &ToFind)
{
char *start = Str.c_str();
char *end = (ptr + Str.Length());

char *ptr = start;
while( ptr < end )
{
if( (end-ptr) < ToFind.Length() )
break;

if( AnsiStrLIComp(ptr, ToFind.c_str(), ToFind.Length()) == 0 )
return ((ptr-start)+1);

++ptr;
}

return 0;
}

AnsiString tmp = "Test String";
int MatchPos = MyPos(tmp, "tes");


Gambit



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.