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.
You can't compare strings in C with ==, because the C compiler does not really have a clue about strings beyond a string-literal.
The _memicmp function compares the first count characters of the two buffers buffer1 and buffer2 byte by byte. The comparison is not case-sensitive.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With