Export (0) Print
Expand All
div
eof
Expand Minimize
This topic has not yet been rated - Rate this topic

_mbsnbcnt, _mbsnbcnt_l, _mbsnccnt, _mbsnccnt_l, _strncnt, _wcsncnt 

Returns the number of characters or bytes within a supplied count.


size_t _mbsnbcnt(
   const unsigned char *str,
   size_t count 
);
size_t _mbsnbcnt_l(
   const unsigned char *str,
   size_t count,
   _locale_t locale
);
size_t _mbsnccnt(
   const unsigned char *str,
   size_t count
);
size_t _mbsnccnt_l(
   const unsigned char *str,
   size_t count,
   _locale_t locale
);
size_t _strncnt(
   const char *str,
   size_t count
);
size_t _wcsncnt(
   const wchar_t *str,
   size_t count
);

Parameters

str

String to be examined.

count

Number of characters or bytes to be examined in str.

locale

Locale to use.

_mbsnbcnt and _mbsnbcnt_l return the number of bytes found in the first count of multibyte characters of str. _mbsnccnt and _mbsnccnt_l return the number of characters found in the first count of bytes of str. If a NULL character is encountered before the examination of str has completed, they return the number of bytes or characters found before the NULL character. If str consists of fewer than count characters or bytes, they return the number of characters or bytes in the string. If count 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 count bytes of the single-byte string str. _wcsncnt returns the number of characters in the first count wide characters of the wide-character string str.

_mbsnbcnt and _mbsnbcnt_l count the number of bytes found in the first count of multibyte characters of str. _mbsnbcnt and _mbsnbcnt_l replace mtob and should be used in place of mtob.

_mbsnccnt and _mbsnccnt_l count the number of characters found in the first count of bytes of str. If _mbsnccnt and _mbsnccnt_l encounter 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 and _mbsnccnt_l replace btom and should be used in place of btom.

If str is a null pointer or is count is 0, these functions invoke the invalid parameter handler as described in Parameter Validation, errno is set to EINVAL, and the function returns 0.

The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale for more information. The versions of these functions without the _l suffix use the current locale for this locale-dependent behavior; the versions with the _l suffix are identical except that they use the locale parameter passed in instead.

Generic-Text Routine Mappings
Routine _UNICODE and _MBCS not defined _MBCS defined _UNICODE defined

_tcsnbcnt

_strncnt

_mbsnbcnt

_wcsncnt

_tcsnccnt

_strncnt

_mbsnbcnt

 n/a

_wcsncnt

 n/a

 n/a

_mbsnbcnt

_wcsncnt

 n/a

 n/a

_mbsnccnt

n/a

n/a

_mbsnbcnt_l

_mbsnccnt_l

Routine Required header Compatibility

_mbsnbcnt

<mbstring.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_mbsnbcnt_l

<mbstring.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_mbsnccnt

<mbstring.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_mbsnccnt_l

<mbstring.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_strncnt

<tchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_wcsncnt

<tchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For more compatibility information, see Compatibility in the Introduction.

// crt_mbsnbcnt.c

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

int 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 %d multibyte characters\n", char_count );
   else
      printf( "The first 10 characters are single-byte.\n");
}
The first 10 characters are single-byte.

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.