Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitive string comparison C++ [duplicate]

Tags:

People also ask

How do you compare two string cases insensitive?

Comparing strings in a case insensitive manner means to compare them without taking care of the uppercase and lowercase letters. To perform this operation the most preferred method is to use either toUpperCase() or toLowerCase() function. toUpperCase() function: The str.

Can I use == to compare strings in C?

You can't compare strings in C with ==, because the C compiler does not really have a clue about strings beyond a string-literal.

Is Memcmp case-insensitive?

The _memicmp function compares the first count characters of the two buffers buffer1 and buffer2 byte by byte. The comparison is not case-sensitive.

Does strcmp ignore case?

The strcasecmp() function compares, while ignoring differences in case, the string pointed to by string1 to the string pointed to by string2. The string arguments to the function must contain a NULL character (\0) marking the end of the string.


I know there are ways to do case ignore comparison that involve iterating through strings or one good one on SO needs another library. I need to put this on other computers that might not have it installed. Is there a way to use the standard libraries to do this? Right now I am just doing...

if (foo == "Bar" || foo == "bar")
{
cout << "foo is bar" << endl;
}

else if (foo == "Stack Overflow" || foo == "stack Overflow" || foo == "Stack overflow" || foo == "etc.")
{
cout << "I am too lazy to do the whole thing..." << endl;
}

This could drastically improve the readability and usability of my code. Thanks for reading this far.