wcscoll
来自 cppreference.cn
在头文件 <wchar.h> 中定义 |
||
int wcscoll( const wchar_t *lhs, const wchar_t *rhs ); |
(C95 起) | |
根据当前安装的区域设置的 LC_COLLATE 类别定义的排序规则,比较两个空终止宽字符串。
目录 |
[编辑] 参数
lhs, rhs | - | 指向要比较的空终止宽字符串的指针 |
[编辑] 返回值
如果 lhs
小于(在...之前)rhs
,则为负值。
0 如果 lhs
等于 rhs
。
如果 lhs
大于(在...之后)rhs
,则为正值。
[编辑] 注意
排序规则是字典顺序:字母在国家字母表中的位置(其等价类)比其大小写或变体具有更高的优先级。在等价类中,小写字符在它们的大写等价物之前排序,并且特定于区域设置的顺序可能适用于带有变音符号的字符。在某些区域设置中,字符组比较为单个排序单元。例如,捷克语中的 "ch" 在 "h" 之后,在 "i" 之前,匈牙利语中的 "dzs" 在 "dz" 之后,在 "g" 之前。
[编辑] 示例
运行此代码
#include <stdio.h> #include <wchar.h> #include <locale.h> void try_compare(const wchar_t* p1, const wchar_t* p2) { if(wcscoll(p1, p2) < 0) printf("%ls before %ls\n", p1, p2); else printf("%ls before %ls\n", p2, p1); } int main(void) { setlocale(LC_ALL, "en_US.utf8"); printf("In the American locale: "); try_compare(L"hrnec", L"chrt"); setlocale(LC_COLLATE, "cs_CZ.utf8"); printf("In the Czech locale: "); try_compare(L"hrnec", L"chrt"); setlocale(LC_COLLATE, "en_US.utf8"); printf("In the American locale: "); try_compare(L"år", L"ängel"); setlocale(LC_COLLATE, "sv_SE.utf8"); printf("In the Swedish locale: "); try_compare(L"år", L"ängel"); }
可能的输出
In the American locale: chrt before hrnec In the Czech locale: hrnec before chrt In the American locale: ängel before år In the Swedish locale: år before ängel