共用方式為


_strnicmp、_wcsnicmp、_mbsnicmp、_strnicmp_l、_wcsnicmp_l、_mbsnicmp_l

比較兩個字串的字元,而不考慮大小寫。

重要

不可在於 Windows 執行階段 中執行的應用程式中使用 _mbsnicmp 和 _mbsnicmp_l。如需詳細資訊,請參閱 /ZW 不支援 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 函式最多會對 string1 和 string2 的前 count 個字元進行序數比較。 系統會將每個字元轉換成小寫來執行比較,而不考慮大小寫。 _strnicmp 是不區分大小寫版本的 strncmp。 如果在比較 count 個字元之前任一字串中已達結束的 null 字元,則會結束比較。 如果字串相等,當比較 count 個字元之前任一字串中已達結束的 null 字元時,較短的字串為較小者。

ASCII 資料表 91 到 96 的字元 ('['、'\'、']'、'^'、'_' 和 '`') 會評估為小於任何字母字元。 這個順序與 stricmp 的順序相同。

_wcsnicmp 和 _mbsnicmp 是寬字元和多位元組字元版本的 _strnicmp。 _wcsnicmp 的引數是寬字元字串,而 _mbsnicmp 的引數則是多位元組字元字串。 _mbsnicmp 根據目前的多位元組字碼頁來辨識多位元組字元序列,並在發生錯誤時傳回 _NLSCMPERROR。 如需詳細資訊,請參閱字碼頁。 除此之外,這三個函式的行為相同。 這些函式會受到地區設定的影響,沒有 _l 後置字元的版本會使用目前的地區設定進行與地區設定相關的行為,而有 _l 後置字元的版本則會改用傳入的 locale。 如需詳細資訊,請參閱地區設定

這些函式全都會驗證它們的參數。 如果 string1 或 string2 是 null 指標,則會叫用無效參數處理常式,如參數驗證中所述。 如果允許繼續執行,這些函式會傳回 _NLSCMPERROR,並將 errno 設為 EINVAL。

一般文字常式對應

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 的範例。

.NET Framework 對等用法

System::String::Compare

請參閱

參考

字串操作 (CRT)

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