0

I have a problem where i want to compare strings, however the comparison cant be case sensitive. I have tried to use

stricmp
strnicmp
strcmpi

They do not seem to be part of the <string> or <cstring> libraries on my compiler. I am using the GNU compiler. Is there a function that will do this?

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Cosa
0

you can use std::transform() to convert the strings to either upper or lower class then use the comparisons

std::string s1 = "Hello";
std::string s2 = "HELLO";

std::transform( s1,begin(),s1.end(),s1.begin(),touper);
std::transform( s2,begin(),s2.end(),s2.begin(),touper);
if(s1 == s2)
{
   // do something
}
0

hey, thnx for that but i found a function that would do it.

strcasecmp(s1,s2)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.