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