Поделиться через


_mbsnbcnt, _mbsnccnt, _strncnt, _wcsncnt

Return number of characters or bytes within a supplied count

size_t_mbsnbcnt(constunsignedchar*string,size_tnumber );

size_t_mbsnccnt(constunsignedchar*string,size_tnumber );

Routine Required Header Compatibility
_mbsnbcnt <mbstring.h> Win 95, Win NT
_mbsnccnt <mbstring.h> Win 95, Win NT
_strncnt <tchar.h> Win 95, Win NT
_wcsncnt <tchar.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

_mbsnbcnt returns the number of bytes found in the first number of multibyte characters of string. _mbsnccnt returns the number of characters found in the first number of bytes of string. If a NULL character is encountered before the examination of string has completed, they return the number of bytes or characters found before the NULL character. If string consists of fewer than number characters or bytes, they return the number of characters or bytes in the string. If number is less than zero, they return 0. In previous versions, these functions had a return value of type int rather than size_t.

_strncnt returns the number of characters in the first number bytes of the single-byte string string. _wcsncnt returns the number of bytes in the first number wide characters of the wide-character string string.

Parameters

string

String to be examined

number

Number of characters or bytes to be examined in string

Remarks

_mbsnbcnt counts the number of bytes found in the first number of multibyte characters of string. _mbsnbcnt replaces mtob, and should be used in place of mtob.

_mbsnccnt counts the number of characters found in the first number of bytes of string. If _mbsnccnt encounters a NULL in the second byte of a double-byte character, the first byte is also considered to be NULL and is not included in the returned count value. _mbsnccnt replaces btom, and should be used in place of btom.

If _MBCS is defined, _mbsnbcnt is mapped to _tcsnbcnt and _mbsnbcnt is mapped to _tcsnccnt. These two mapping routines provide generic-text support and are defined in TCHAR.H. If _UNICODE is defined, both _mbsnbcnt and _mbsnccnt are mapped to the _wcsncnt macro. When _MBCS and _UNICODE are not defined, both _tcsnbcnt and _tcsnccnt are mapped to the _strncnt macro. _strncnt is the single-byte–character string version and _wcsncnt is the wide-character–string version of these mapping routines. _strncnt and _wcsncnt are provided only for generic-text mapping and should not be used otherwise. For more information, see Using Generic-Text Mappings and see Appendix B, Generic-Text Mappings.

Example

/* MBSNBCNT.C */

#include  <mbstring.h>
#include  <stdio.h>

void main( void )
{
   unsigned char str[] = "This is a multibyte-character string.";
   unsigned int char_count, byte_count;
   char_count = _mbsnccnt( str, 10 );
   byte_count = _mbsnbcnt( str, 10 );
   if ( byte_count - char_count )
      printf( "The first 10 characters contain %s multibyte characters", char_count );
   else
      printf( "The first 10 characters are single-byte.");
}

Output

The first 10 characters are single-byte.

String Manipulation Routines

See Also   _mbsnbcat