|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
_strnicmp, _wcsnicmp, _mbsnicmp
Compare characters of two strings without regard to case.
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 );
- string1, string2
- Null-terminated strings to compare.
- Number of characters to compare.
Indicates the relationship between the substrings as follows.
|< 0||string1 substring less than string2 substring|
|0||string1 substring identical to string2 substring|
|> 0||string1 substring greater than string2 substring|
On an error, _mbsnicmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.
The _strnicmp function lexicographically compares, at most, the first count characters of string1 and string2. The comparison is performed without regard to case; _strnicmp is a case-insensitive version of strncmp. The comparison ends if a terminating null character is reached in either string before count characters are compared. If the strings are equal when a terminating null character is reached in either string before count characters are compared, the shorter string is lesser.
Two strings containing characters located between 'Z' and 'a' in the ASCII table ('[', '\', ']', '^', '_', and '`') compare differently, depending on their case. For example, the two strings
"ABCD^" compare one way if the comparison is lowercase (
"abcd^") and the other way (
"ABCD^") if it is uppercase.
_wcsnicmp and _mbsnicmp are wide-character and multibyte-character versions of _strnicmp. The arguments and return value of _wcsnicmp are wide-character strings; those of _mbsnicmp are multibyte-character strings. _mbsnicmp recognizes multibyte-character sequences according to the current multibyte code page and returns _NLSCMPERROR on an error. For more information, see Code Pages. These three functions behave identically otherwise. These functions are affected by the current locale setting.
Generic-Text Routine Mappings
|TCHAR.H routine||_UNICODE & _MBCS not defined||_MBCS defined||_UNICODE defined|
|_strnicmp||<string.h>||Win 98, Win Me, Win NT, Win 2000, Win XP|
|_wcsnicmp||<string.h> or <wchar.h>||Win 98, Win Me, Win NT, Win 2000, Win XP|
|_mbsnicmp||<mbstring.h>||Win 98, Win Me, Win NT, Win 2000, Win XP|
For additional compatibility information, see Compatibility in the Introduction.
All versions of the C run-time libraries.
See the example for strncmp.