Share via


_mbsnbicmp

int_mbsnbicmp(constunsignedchar*string1,constunsignedchar*string2,size_tcount**);**

Routine Required Header Compatibility
_mbsnbicmp <mbstring.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

The return value indicates the relationship between the substrings.

Return Value Description
< 0 string1 substring less than string2 substring
0 string1 substring identical to string2 substring
> 0 string1 substring greater than string2 substring

On an error, _mbsnbcmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.

Parameters

string1, string2

Null-terminated strings to compare

count

Number of bytes to compare

Remarks

The _mbsnbicmp function lexicographically compares, at most, the first count bytes of string1 and string2. The comparison is performed without regard to case; _mbsnbcmp is a case-sensitive version of _mbsnbicmp. 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.

_mbsnbicmp is similar to _mbsnicmp, except that it compares strings by bytes instead of by characters.

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 "ABCDE" and "ABCD^" compare one way if the comparison is lowercase ("abcde" > "abcd^") and the other way ("ABCDE" < "ABCD^") if it is uppercase.

_mbsnbicmp recognizes multibyte-character sequences according to the multibyte code page currently in use. It is not affected by the current locale setting.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcsnicmp _strnicmp _mbsnbicmp _wcsnicmp

Example

/* STRNBCMP.C */
#include <mbstring.h>
#include <stdio.h>

char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown fox jumps over the lazy dog";

void main( void )
{
   char tmp[20];
   int result;
   printf( "Compare strings:\n\t\t%s\n\t\t%s\n\n", string1, string2 );
   printf( "Function:\t_mbsnbcmp (first 10 characters only)\n" );
   result = _mbsncmp( string1, string2 , 10 );
   if( result > 0 )
      _mbscpy( tmp, "greater than" );
   else if( result < 0 )
      _mbscpy( tmp, "less than" );
   else
      _mbscpy( tmp, "equal to" );
   printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
   printf( "Function:\t_mbsnicmp _mbsnicmp (first 10 characters only)\n" );
   result = _mbsnicmp( string1, string2, 10 );
   if( result > 0 )
      _mbscpy( tmp, "greater than" );
   else if( result < 0 )
      _mbscpy( tmp, "less than" );
   else
      _mbscpy( tmp, "equal to" );
   printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
}

Output

Compare strings:
      The quick brown dog jumps over the lazy fox
      The QUICK brown fox jumps over the lazy dog

Function:   _mbsnbcmp (first 10 characters only)
Result:      String 1 is greater than string 2

Function:   _mbsnicmp (first 10 characters only)
Result:      String 1 is equal to string 2

String Manipulation Routines

See Also   _mbsnbcat, _mbsnbcmp,_stricmp