_strncoll, _wcsncoll, _mbsncoll, _strncoll_l, _wcsncoll_l, _mbsncoll_l

使用特定于区域设置的信息比较字符串。

重要

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

语法

int _strncoll(
   const char *string1,
   const char *string2,
   size_t count
);
int _wcsncoll(
   const wchar_t *string1,
   const wchar_t *string2,
   size_t count
);
int _mbsncoll(
   const unsigned char *string1,
   const unsigned char *string2,
   size_t count
);
int _strncoll_l(
   const char *string1,
   const char *string2,
   size_t count,
   _locale_t locale
);
int _wcsncoll_l(
   const wchar_t *string1,
   const wchar_t *string2,
   size_t count,
   _locale_t locale
);
int _mbsncoll_l(
   const unsigned char *string1,
   const unsigned char *string2,
   size_t count,
   _locale_t locale
);

参数

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

count
要比较的字符数。

locale
要使用的区域设置。

返回值

其中每个函数返回一个值,该值指示 string1string2 的子字符串的关系,如下所示。

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

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

备注

其中每个函数根据当前使用的代码页对 countstring1 中的前 string2 个字符进行区分大小写比较。 仅在以下情况下使用这些函数:代码页中的字符集顺序和字典字符顺序存在差异,并且此差异对字符串比较很重要。 字符集顺序与区域设置相关。 不带 _l 后缀的函数版本使用当前区域设置,而带 _l 后缀的函数版本使用已传入的区域设置。 有关详细信息,请参阅 Locale

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

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

一般文本例程映射

TCHAR.H 例程 _UNICODE_MBCS 未定义 _MBCS 已定义 _UNICODE 已定义
_tcsnccoll _strncoll _mbsncoll _wcsncoll
_tcsncoll _strncoll _mbsnbcoll _wcsncoll

要求

例程 必需的标头
_strncoll_strncoll_l <string.h>
_wcsncoll_wcsncoll_l <wchar.h> 或 <string.h>
_mbsncoll_mbsncoll_l <mbstring.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