wcsspn() — Find Offset of First Non-matching Wide Character

Format

#include <wchar.h>
size_t wcsspn(const wchar_t *string1, const wchar_t *string2);

Language Level: ANSI

Threadsafe: Yes

Wide Character Function: See Wide Characters for more information.

Description

The wcsspn() function 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.

Return Value

The wcsspn() function returns the number of wide characters in the segment.

Example that uses wcsspn()

This example finds the first occurrence in the array string of a wide character that is not an a, b, or c. Because the string in this example is cabbage, the wcsspn() function 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 );
}
 
/****************  Output should be similar to:  ******************
 
The first 5 characters of "cabbage" are found in "abc"
*/

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]