开发者

How do I make a case insensitive compare between two Unicode characters or strings under Windows in C/C++?

I'm looking for a way of doing a insensitive compare of two Unicode char开发者_如何学运维acters (char32) under Windows (C/C++, not .NET).

I am aware that the solution is supposed to be locale aware.

I would like a solution that would not require additional third-party libraries.


My first thought is that you should lookup CompareStringEx with its parameters LOCALE_INVARIANT and NORM_IGNORECASE.


Whoops, you want to compare char32s. Ignore my post.

My original answer

For posterity:

You can use

_wcsicmp(const wchar_t *string1, const wchar_t *string2) or

_mbsicmp(const unsigned char_t *string1, const unsigned char *string2)

the former compares wide characters (usually UTF-16) and the latter compares multi-byte characters (usually UTF-8). You need to set the code page using

_setmbcp(int codepage)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜