wcscspn() — Find offset of first wide-character match

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 wcscspn(const wchar_t *string1, const wchar_t *string2);

General description

Determines the number of wide characters in the initial segment of the string pointed to by string1 that do not appear in the string pointed to by string2. The wcscspn() function operates on NULL-terminated wide-character strings. The string arguments to these functions must contain a NULL wide character marking the end of the string.

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

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

Example

CELEBW09
⁄* CELEBW09                                      

   This example uses &wcscspn. to find the first occurrence of                  
   any of the characters a, x, l, or e in string.                               
                                                                                
 *⁄                                                                             
#include <stdio.h>                                                              
#include <wchar.h>                                                              
                                                                                
#define SIZE    40                                                              
                                                                                
int main(void)                                                                  
{                                                                               
  wchar_t string[ SIZE ] = L"This is the source string";                        
  wchar_t * substring = L"axle";                                                
                                                                                
  printf( "The first %i characters in the string \"%ls\" are not in the "       
          "string \"%ls\" \n", wcscspn( string, substring),                     
          string, substring );                                                  
}                                                                               
Output:
The first 10 characters in the string "This is the source string" are not
in the string "axle"

Related information