wcsspn() — Search for wide characters in a string

Standards

Standards / Extensions C or C++ Dependencies

ISO C Amendment
XPG4
XPG4.2
C99
Single UNIX Specification, Version 3

both  

Format

#include <wchar.h>

size_t wcsspn(const wchar_t *string1, const wchar_t *string2);

General description

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.

Returned value

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

Example

CELEBW19
⁄* 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 );                                          
}                                                                               
Output:
The first 5 characters of "cabbage" are found in "abc"

Related information