Share via


strcoll, wcscoll, _mbscoll, _strcoll_l, _wcscoll_l, _mbscoll_l

使用目前的地區設定或指定的 LC_COLLATE 轉換狀態分類來比較字串。

重要

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

參數

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

locale
要使用的地區設定。

傳回值

每個函式都會傳回值,指出 與 string2 的關聯性 string1 ,如下所示。

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

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

備註

所有這些函式都會根據目前使用的字碼頁來執行 string2string1 的區分大小寫比較。 只有在目前字碼頁中的字元集順序與語彙字元順序之間有差異,而且字串比較有此差異時,才應該使用這些函式。

這些函式全都會驗證它們的參數。 string1如果 或 string2 為 Null 指標,或 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
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