string::find() function for case insensitive search
-
Hi to All, I have used the find() function of string lib in my program. Now my problem is I need to search for case insensitive sub string. Please help me to convert my code . My code sample is......... string::size_type loc=Myword.find("TaG"); //searching if tag/Tag/tAg...is present in the string if(loc!= string::npos) { //tag is present } else { //"tag absent"; } thanks in advance HimangshuS
----------------------------- I am a beginner
-
Hi to All, I have used the find() function of string lib in my program. Now my problem is I need to search for case insensitive sub string. Please help me to convert my code . My code sample is......... string::size_type loc=Myword.find("TaG"); //searching if tag/Tag/tAg...is present in the string if(loc!= string::npos) { //tag is present } else { //"tag absent"; } thanks in advance HimangshuS
----------------------------- I am a beginner
You have two options Override your own string type that's case insensitive: Clicky[^] Or just make lower case copies of the string and substring, and use find with those.
Help me! I'm turning into a grapefruit! Buzzwords!
-
Hi to All, I have used the find() function of string lib in my program. Now my problem is I need to search for case insensitive sub string. Please help me to convert my code . My code sample is......... string::size_type loc=Myword.find("TaG"); //searching if tag/Tag/tAg...is present in the string if(loc!= string::npos) { //tag is present } else { //"tag absent"; } thanks in advance HimangshuS
----------------------------- I am a beginner
You can maybe try this function
StrStrI
. It's takes two buffers look up MSDN. So when you call this function pass instd::string
likewise...StrStrI( &Myword[0], "TaG" );
If successfull it will return address of the substring, else NULL. Header to include: Declared in Shlwapi.h. Import Library: Shlwapi.lib. Also make sure you don't modify the length of
Myword
buffer. std::string is not aware of any such updates.Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
-
You have two options Override your own string type that's case insensitive: Clicky[^] Or just make lower case copies of the string and substring, and use find with those.
Help me! I'm turning into a grapefruit! Buzzwords!
is there any function to make the string lowercase before comparing..say string a="HI How R U" if(a.find("hi")) //here I want to convert the string into lowercase n compare with lowercase hi { cout<<"found"; } thanks
----------------------------- I am a beginner
-
You can maybe try this function
StrStrI
. It's takes two buffers look up MSDN. So when you call this function pass instd::string
likewise...StrStrI( &Myword[0], "TaG" );
If successfull it will return address of the substring, else NULL. Header to include: Declared in Shlwapi.h. Import Library: Shlwapi.lib. Also make sure you don't modify the length of
Myword
buffer. std::string is not aware of any such updates.Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
thanks for your reply... Actually if you dont mind I need little more clearence. I didnot get how do I use strstrI in the same line if(myword.find("Tag")!= string::npos) All we need is to incorporate case insensitive search in the same statement above. (Or can we pass the lowercase of myword itself so that we can check with "tag" always)...something like if(lcase(myword).find("Tag")!= string::npos) myword is of the type string thanks in advance
----------------------------- I am a beginner
-
thanks for your reply... Actually if you dont mind I need little more clearence. I didnot get how do I use strstrI in the same line if(myword.find("Tag")!= string::npos) All we need is to incorporate case insensitive search in the same statement above. (Or can we pass the lowercase of myword itself so that we can check with "tag" always)...something like if(lcase(myword).find("Tag")!= string::npos) myword is of the type string thanks in advance
----------------------------- I am a beginner
himangshuS wrote:
if(myword.find("Tag")!= string::npos)
Like this...
if( StrStrI( &Myword[0], "Tag" ))
{
MessageBox( "Found \"Tag\" in Myword :)" );
}Nibu babu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com