function
<cwchar>

wcsspn

size_t wcsspn (const wchar_t* wcs1, const wchar_t* wcs2);
Get span of character set in wide string
Returns the length of the initial portion of wcs1 which consists only of wide characters that are part of wcs2.

The search does not include the terminating null wide characters of either strings, but ends there.

This is the wide character equivalent of strspn (<cstring>).

Parameters

wcs1
C wide string to be scanned.
wcs2
C wide string containing the characters to match.

Return value

The length of the initial portion of wcs1 containing only wide characters that appear in wcs2.
Therefore, if all of the wide characters in wcs1 are in wcs2, the function returns the length of the entire wcs1 wide string, and if the first wide character in wcs1 is not in wcs2, the function returns zero.
size_t is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
/* wcsspn example */
#include <wchar.h>

int main ()
{
  int i;
  wchar_t wcsText[] = L"129th";
  wchar_t wcsSet[] = L"1234567890";

  i = wcsspn (wcsText,wcsSet);
  wprintf (L"The initial number has %d digits.\n",i);
  return 0;
}

Output:

The initial number has 3 digits.


See also