_mbsnbcnt, _mbsnccnt, _strncnt, _wcsncnt

From RAD Studio
Jump to: navigation, search

Go Up to string.h Index


Header File

mbstring.h

Category

Memory and String Manipulation Routines

Prototype

size_t _mbsnbcnt(const unsigned char * str, size_t nmbc);

size_t _mbsnccnt(const unsigned char * str, size_t nbyte);

Description

If _MBCS is defined:

  • _mbsnbcnt is mapped to the portable macro _tcsnbcnt.
  • _mbsnccnt is mapped to the portable macro _tcsnccnt.

If _UNICODE is defined:

  • Both _mbsnbcnt and _mbsnccnt are mapped to the _wcsncnt macro.

If neither _MBCS nor _UNICODE is defined, _tcsnbcnt and _tcsnccnt are mapped to the _strncnt macro. _strncnt is the single-byte version of these functions and _wcsncnt is the wide-character version of these functions. _strncnt and _wcsncnt are available only for generic-text mappings. They should not be used directly.

_mbsnbcnt examines the first nmbc multibyte characters of the str argument. The function returns the number of bytes found in those characters.

_mbsnccnt examines the first nmbc bytes of the str argument. The function returns the number of characters found in those bytes. If NULL is encountered in the second byte of a multibyte character, the whole character is considered NULL and will not be included in the return value.

Each of the functions ends its examination of the str argument if NULL is reached before the specified number of characters or bytes is examined.

If str has fewer than the specified number of characters or bytes, the function returns the number of characters or bytes found in str.

Return Value

_mbsnbcnt returns the number of bytes found.

_mbsnccnt returns the number of characters found.

If nmbc or nbyte is less than zero, the functions return 0.

Example

#include <mbstring.h>
#include <iostream>
using namespace std;

int main()
{
	 unsigned char str[]="Hello world! ";
	 int n_charact, n_byte;
	 n_byte=_mbsnbcnt(str, 5);
	 n_charact=_mbsnccnt(str, 5);
	 cout<<"The first 5 multibyte characters of \""<<str<<"\" contain "<<n_byte<<" bytes."<<endl;
	 cout<<"The first 5 bytes of \""<<str<<"\" contain "<<n_charact<<" characters."<<endl;

	return 0;
}