strcspn

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

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

Syntax

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

Parameters

str
(IN) Points to the string to be scanned.
charset
(IN) Points to the set of characters for which to search.

Return Values

The strcspn function returns the offset position in a string where the first occurrence of charset begins.

Remarks

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

See Also

strspn

Example

  #include <string.h>  
   
  main ()  
  {  
     printf ("%d\n", strcspn ("abcbcadef", "cba") );  
     printf ("%d\n", strcspn ("xxxbcadef", "cba") );  
     printf ("%d\n", strcspn ("123456789", "cba") );  
  }
  

produces the following:

  0  
  3  
  9