wcscoll
|
定义于头文件
<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