Xi Xu's More Things

wcscoll

来自cppreference.com
< c‎ | string‎ | wide
 
 
 
空终止宽字符串
函数
字符操作
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C99)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
转换成数值格式
(C95)(C99)
(C95)(C99)
(C99)(C95)(C99)
(C99)(C99)
字符串操作
(C95)(C11)
(C95)(C11)
(C95)(C11)
(C95)(C11)
(C95)(C11)
(C95)
(C95)
(C95)
wcscoll
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)(C11)
数组操作
(C95)(C11)
(C95)(C11)
(C95)
(C95)
(C95)
 
在标头 <wchar.h> 定义
int wcscoll( const wchar_t *lhs, const wchar_t *rhs );
(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

引用

  • C11 标准(ISO/IEC 9899:2011):
  • 7.29.4.4.2 The wcscoll function (第 433-434 页)
  • C99 标准(ISO/IEC 9899:1999):
  • 7.24.4.4.2 The wcscoll function (第 379-380 页)

参阅

比较两个字符串,根据当前本地环境
(函数)
(C95)
变换宽字符串,使得 wcscmp 会产生与 wcscoll 相同的结果
(函数)
(C95)
比较两个宽字符串
(函数)