wcsicmp fails

Started by
4 comments, last by vladic2000x 14 years, 5 months ago
I'm trying to compare without taking into account the case of the characters, two russian strings, and the "_wcsicmp" function returns -2, which means different. if(_wcsicmp(L"3 Мяч",L"3 мяч")!=0) { assert(0); } does anyone give me a hint?
Advertisement
Have you set the appropriate locale before making the comparison?

Doing this before the comparison makes it pass for me (apologies if this isn't the right locale setting, just guessing):
setlocale(LC_CTYPE, "rus");
That's terrible... How would I know that I need to set the locale? Nothing about that in MSDN and I thought that the wide string version are universal..

Thanks mattd.
Quote:Original post by vladic2000x
That's terrible... How would I know that I need to set the locale? Nothing about that in MSDN and I thought that the wide string version are universal..


It does say in the MSDN:
Quote:Remarks
The _stricmp function lexicographically compares lowercase versions of string1 and string2 and returns a value indicating their relationship. _stricmp differs from _stricoll in that the _stricmp comparison is affected by LC_CTYPE, whereas the _stricoll comparison is according to the LC_CTYPE and LC_COLLATE categories of the current locale. For more information on the LC_COLLATE category, see setlocale and Locale Categories.
It's impossible to create a universal case insensitive comparison, since different languages have different rules for cases. For example, in some languages the upper case of ü is Ü, but in others it's UE.
I appologize for criticizing the MSDN. Indeed it is written about what Evil Steve said. :)

This topic is closed to new replies.

Advertisement