Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C Amendment |
both |
#include <wchar.h>
size_t wcsspn(const wchar_t *string1, const wchar_t *string2);
Computes the number of wide characters in the initial segment of the string pointed to by string1, which consists entirely of wide characters from the string pointed to by string2.
The behavior of this wide-character function is affected by the LC_CTYPE category of the current locale. If you change the category, undefined results can occur.
wcsspn() returns the number of wide characters in the segment.
⁄* CELEBW19
This example finds the first occurrence in the array string
of a character that is neither an a, b, nor c. Because the
string in this example is cabbage, &wcsspn. returns 5, the
index of the segment of cabbage before a character that is
not an a, b, or c.
*⁄
#include <stdio.h>
#include <wchar.h>
int main(void)
{
wchar_t * string = L"cabbage";
wchar_t * source = L"abc";
int index;
index = wcsspn( string, L"abc" );
printf( "The first %d characters of \"%ls\" are found in \"%ls\"\n",
index, string, source );
}
The first 5 characters of "cabbage" are found in "abc"