C参考手册
字符串 | Strings
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
参考
- C11标准(ISO/IEC 9899:2011):
- 7.29.4.4.2 wcscoll函数(p: 433-434)
- C99标准(ISO/IEC 9899:1999):
- 7.24.4.4.2 wcscoll函数(p: 379-380)
另请参阅
与strcoll |
根据当前语言环境(函数)比较两个字符串 |
---|---|
wcsxfrm(C95) |
转换宽字符串以使wcscmp产生与wcscoll(函数)相同的结果 |
wcscmp(C95) |
比较两个宽字符串(函数) |
| C ++文档wcscoll |