_strnicmp
, _wcsnicmp
, _mbsnicmp
, _strnicmp_l
, _wcsnicmp_l
, _mbsnicmp_l
比較兩個字串的指定數目的字元,而不考慮大小寫。
重要
在 Windows 執行階段中執行的應用程式中無法使用 _mbsnicmp
和 _mbsnicmp_l
。 如需詳細資訊,請參閱 CRT functions not supported in Universal Windows Platform apps (通用 Windows 平台應用程式中不支援的 CRT 函式)。
語法
int _strnicmp(
const char *string1,
const char *string2,
size_t count
);
int _wcsnicmp(
const wchar_t *string1,
const wchar_t *string2,
size_t count
);
int _mbsnicmp(
const unsigned char *string1,
const unsigned char *string2,
size_t count
);
int _strnicmp_l(
const char *string1,
const char *string2,
size_t count,
_locale_t locale
);
int _wcsnicmp_l(
const wchar_t *string1,
const wchar_t *string2,
size_t count,
_locale_t locale
);
int _mbsnicmp_l(
const unsigned char *string1,
const unsigned char *string2,
size_t count,
_locale_t locale
);
參數
string1
, string2
以 Null 結束的待比較字串。
count
要比較的字元數。
locale
要使用的地區設定。
傳回值
表示子字串之間的關聯性,如下所示。
傳回值 | 描述 |
---|---|
< 0 | string1 子字串小於 string2 子字串。 |
0 | string1 子字串等於 string2 子字串。 |
> 0 | string1 子字串大於 string2 子字串。 |
在參數驗證錯誤上,這些函式會傳回 _NLSCMPERROR
,其定義于 < string.h 和 < mbstring.h >> 中。
備註
函 _strnicmp
式最多會比較 和 string2
的第一 count
個字元 string1
。 系統會將每個字元轉換成小寫來執行比較,而不考慮大小寫。 _strnicmp
是不區分大小寫版本的 strncmp
。 如果在比較 count
個字元之前任一字串中已達結束的 null 字元,則會結束比較。 如果字串相等,當比較 count
個字元之前任一字串中已達結束的 null 字元時,較短的字串為較小者。
ASCII 資料表中 91 到 96 的字元('['、'\'、']'、'^'、'_' 和 ''') 會評估為小於任何字母字元。 這個順序與 stricmp
的順序相同。
_wcsnicmp
和 _mbsnicmp
分別是 _strnicmp
的寬字元版本和多位元組字元版本。 的引數 _wcsnicmp
是寬字元字串。 的引數 _mbsnicmp
是多位元組字元字串。 _mbsnicmp
根據目前的多位元組字碼頁來辨識多位元組字元序列,並在發生錯誤時傳回 _NLSCMPERROR
。 如需詳細資訊,請參閱 字碼頁 。 除此之外,這三個函式的行為相同。 這些函式會受到地區設定的影響,沒有 _l
後置字元的版本會使用目前的地區設定進行與地區設定相關的行為,而有 _l
後置字元的版本則會改用傳入的 locale
。 如需詳細資訊,請參閱 Locale。
這些函式全都會驗證它們的參數。 string1
如果 或 string2
為 Null 指標,則會叫用不正確參數處理常式,如參數驗證 中所述 。 如果允許繼續執行,這些函式會傳回 _NLSCMPERROR
,並將 errno
設為 EINVAL
。
根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
泛型文字常式對應
TCHAR.H 常式 | _UNICODE 和 _MBCS 未定義 |
_MBCS 定義 |
_UNICODE 定義 |
---|---|---|---|
_tcsncicmp |
_strnicmp |
_mbsnicmp |
_wcsnicmp |
_tcsnicmp |
_strnicmp |
_mbsnbicmp |
_wcsnicmp |
_tcsncicmp_l |
_strnicmp_l |
_mbsnicmp_l |
_wcsnicmp_l |
需求
常式 | 必要的標頭 |
---|---|
_strnicmp , _strnicmp_l |
<string.h> |
_wcsnicmp , _wcsnicmp_l |
<string.h > 或 < wchar.h> |
_mbsnicmp , _mbsnicmp_l |
<mbstring.h> |
如需相容性詳細資訊,請參閱相容性。
範例
請參閱 的 strncmp
範例。
另請參閱
字串操作
strcat
, wcscat
, _mbscat
strcmp
, wcscmp
, _mbscmp
strcpy
, wcscpy
, _mbscpy
strncat
, _strncat_l
, wcsncat
, _wcsncat_l
, _mbsncat
, _mbsncat_l
strncmp
, wcsncmp
, _mbsncmp
, _mbsncmp_l
strncpy
, _strncpy_l
, wcsncpy
, _wcsncpy_l
, _mbsncpy
, _mbsncpy_l
strrchr
, wcsrchr
, _mbsrchr
, _mbsrchr_l
_strset
, _strset_l
, _wcsset
, _wcsset_l
, _mbsset
, _mbsset_l
strspn
, wcsspn
, _mbsspn
, _mbsspn_l
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應