strspn

Computes the length of the initial segment of a string consisting of characters from a given set

Local Servers:nonblocking
Remote Servers:N/A
Classification:ANSI
Service:String Manipulation

Syntax

  #include <string.h>  
   
  size_t strspn  (  
     const char   *str,   
     const char   *charset);
  

Parameters

str
(IN) Points to the string for which to compute the length of the initial segment.
charset
(IN) Points to a set of characters.

Return Values

The strspn function returns the offset from the beginning of the string str where the characters in charset have ended.

Remarks

The strspn function computes the length of the initial segment of the string pointed to by str, which consists of characters from the string pointed to by charset. The terminating NULL character is not considered to be part of charset.

See Also

strcspn, strpbrk

Example

  #include <string.h>  
  #include <stdio.h>  
   
  main ()  
  {  
     printf ("%d\n", strspn ("out to lunch", "aeiou") );  
     printf ("%d\n", strspn ("out to lunch", "xyz") );  
  }
  

produces the following:

   2  
   0