wcscoll
来自cppreference.com
| 在标头 <wchar.h> 定义
|
||
| |
(C95 起) | |
按照当前安装的本地环境的 LC_COLLATE 类别所定义的校排顺序,比较两个空终止宽字符串。
参数
| lhs, rhs | - | 指向要比较的空终止宽字符串的指针 |
返回值
若 lhs 小于(前趋)rhs 则为负值。
若 lhs 等于 rhs 则为 0。
若 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