命名空间
变体
操作

wcscoll

来自 cppreference.cn
< c‎ | string‎ | wide
在头文件 <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)

[编辑] 参见

根据当前区域设置比较两个字符串
(函数) [编辑]
转换宽字符串,以便 wcscmp 产生与 wcscoll 相同的结果
(函数) [编辑]
(C95)
比较两个宽字符串
(函数) [编辑]
C++ 文档 关于 wcscoll