Share via


_strncoll, _wcsncoll, _mbsncoll, _strncoll_l, _wcsncoll_l, _mbsncoll_l

使用地區設定特定資訊,以比較字串。

重要

在 Windows 執行階段中執行的應用程式中無法使用 _mbsncoll_mbsncoll_l。 如需詳細資訊,請參閱 CRT functions not supported in Universal Windows Platform apps (通用 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
);

參數

string1, string2
以 Null 結束的待比較字串。

count
要比較的字元數。

locale
要使用的地區設定。

傳回值

所有這些函式都會傳回值,而值表示 string1 子字串和 string2 子字串的關聯性,如下所示。

傳回值 與 的 string1 關聯性 string2
< 0 string1 小於 string2
0 string1 等同於 string2
> 0 string1 大於 string2

所有這些函式都會傳回 _NLSCMPERROR。 若要使用 _NLSCMPERROR,請包括 STRING.h 或 MBSTRING.h。 如果 string1string2 包含定序順序之網域外部的寬字元碼,則 _wcsncoll 可能會失敗。 發生錯誤時,_wcsncoll 可能會將 errno 設定為 EINVAL。 若要檢查 呼叫 _wcsncoll 時是否有錯誤,請將 設定 errno 為 0,然後在呼叫之後 _wcsncoll 檢查 errno

備註

所有這些函式都會根據目前使用中的字碼頁來執行 string1string2 中第一個 count 字元的區分大小寫比較。 只有在字碼頁中的字元集順序與語彙字元順序之間有差異,以及當此差異對字串比較很重要時,才使用這些函式。 字元集順序是地區設定相關。 這些沒有 _l 後置詞之函式的版本會使用目前的地區設定,但具有 _l 後置詞的版本會使用傳入的地區設定。 如需詳細資訊,請參閱 Locale

這些函式全都會驗證它們的參數。 string1如果 或 string2 為 Null 指標,或 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
strcmp, wcscmp, _mbscmp
_stricmp, _wcsicmp, _mbsicmp, _stricmp_l, _wcsicmp_l, _mbsicmp_l
strncmp, wcsncmp, _mbsncmp, _mbsncmp_l
_strnicmp, _wcsnicmp, _mbsnicmp, _strnicmp_l, _wcsnicmp_l, _mbsnicmp_l
strxfrm, wcsxfrm, _strxfrm_l, _wcsxfrm_l