strcoll, wcscoll, _mbscoll, _strcoll_l, _wcscoll_l, _mbscoll_l

使用当前区域设置或指定的 LC_COLLATE 转换状态类别比较字符串。

重要

_mbscoll_mbscoll_l 无法用于在 Windows 运行时中执行的应用程序。 有关详细信息,请参阅通用 Windows 平台应用中不支持的 CRT 函数

语法

int strcoll(
   const char *string1,
   const char *string2
);
int wcscoll(
   const wchar_t *string1,
   const wchar_t *string2
);
int _mbscoll(
   const unsigned char *string1,
   const unsigned char *string2
);
int _strcoll_l(
   const char *string1,
   const char *string2,
   _locale_t locale
);
int wcscoll_l(
   const wchar_t *string1,
   const wchar_t *string2,
   _locale_t locale
);
int _mbscoll_l(
   const unsigned char *string1,
   const unsigned char *string2,
   _locale_t locale
);

参数

string1string2
要比较的 null 终止的字符串。

locale
要使用的区域设置。

返回值

其中每个函数均返回一个指示 string1string2 之间关系的值,如下所示。

返回值 string1string2 的关系
< 0 string1 小于 string2
0 string1 等于 string2
> 0 string1 大于 string2

其中每个函数在错误时返回 _NLSCMPERROR。 若要使用 _NLSCMPERROR,请包括 STRING.H 或 MBSTRING.H。 如果 string1string2NULL 或包含排序序列域外部的宽字符代码,则 wcscoll 会失败。 发生错误时,wcscoll 可能会将 errno 设置为 EINVAL。 若要检查有关调用 wcscoll 的错误,请将 errno 设置为 0,然后在调用 wcscoll 后检查 errno

备注

其中每个函数根据当前使用的代码页对 string1string2 进行区分大小写比较。 仅在当前代码页中的字符集顺序与字典字符顺序之间存在差异,并且此差异对于字符串比较有关系时,才应使用这些函数。

所有这些函数都验证其参数。 如果 string1string2 为空指针,或如果 count 大于 INT_MAX,则调用无效参数处理程序,如参数验证中所述。 如果允许执行继续,则这些函数将返回 _NLSCMPERROR 并将 errno 设置为 EINVAL

两个字符串的比较是一个与区域设置相关的操作,因为每个区域设置对排序字符有不同的规则。 这些不带 _l 后缀的函数的版本使用当前线程的区域设置实现与该区域设置相关的行为;带有 _l 后缀的版本与不带此后缀的相应函数相同,只不过它们使用作为参数传递的区域设置(而不是当前区域设置)。 有关详细信息,请参阅 Locale

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态

一般文本例程映射

TCHAR.H 例程 _UNICODE_MBCS 未定义 _MBCS 已定义 _UNICODE 已定义
_tcscoll strcoll _mbscoll wcscoll

要求

例程 必需的标头
strcoll <string.h>
wcscoll <wchar.h>、<string.h>
_mbscoll_mbscoll_l <mbstring.h>
_strcoll_l <string.h>
_wcscoll_l <wchar.h>、<string.h>

有关兼容性的详细信息,请参阅 兼容性

另请参阅

区域设置
字符串操作
strcoll 函数
localeconv
_mbsnbcoll_mbsnbcoll_l_mbsnbicoll_mbsnbicoll_l
setlocale_wsetlocale
strcmpwcscmp_mbscmp
_stricmp_wcsicmp_mbsicmp_stricmp_l_wcsicmp_l_mbsicmp_l
strncmpwcsncmp_mbsncmp_mbsncmp_l
_strnicmp_wcsnicmp_mbsnicmp_strnicmp_l_wcsnicmp_l_mbsnicmp_l
strxfrmwcsxfrm_strxfrm_l_wcsxfrm_l