-
comparing strings
I want to compare 2 strings. Is there a method to compare strings that is not case sensitive? Java has one but I don't know about c++. I'm using .compare( "xxxx" ) and its case sensitive. I also just tried to convert all my strings to lowecase using strlwr( a ) where a: String a="some string" but I get an error saying the function doesnt take a string. I'm using MS Visual C++
thanks,
xer
-
Code:
#include <iostream>
#include <string>
using namespace std;
string str1, str2;
str1 = "ABC";
str2 = "abc";
if (!strcmpi(str1.c_str(), str2.c_str()))
cout << "Strings are the same.";
else
cout << "Strings are different.";
return 0;
strcmpi() is a non case sensitive string comparison function which returns 0 if the strings are the same, negative if str1 is lesser than str2, and positive if str1 is greater than str2.