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?

Recommended Answers

All 2 Replies

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
}

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

strcasecmp(s1,s2)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.