strcspn -- Compare Strings for Substrings

Format

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

Language Level: ANSI, POSIX, XPG4
strcspn finds the first occurrence of a character in string1 that belongs to the set of characters specified by string2. Ending null characters are not considered in the search.

The strcspn function operates on null-terminated strings. The string arguments to the function should contain a null character (\0) marking the end of the string.

Return Value
strcspn returns the index of the first character found. This value is equivalent to the length of the initial substring of string1 that consists entirely of characters not in string2.

Example
This example uses strcspn to find the first occurrence of any of the characters a, x, l or e in string.

#include <stdio.h>
#include <string.h>
#define SIZE    40
int main(void)
{
  char string[ SIZE ] = "This is the source string";
  char * substring = "axle";
  printf( "The first %i characters in the string \"%s\" "
          "are not in the string \"%s\" \n",
            strcspn(string, substring), string, substring);
  return 0;
  /*********************************************************************
     The output should be:
     The first 10 characters in the string "This is the source string"
     are not in the string "axle"
  *********************************************************************/
}


strcat -- Concatenate Strings
strchr -- Search for Character
strcmp -- Compare Strings
strcmpi -- Compare Strings Without Case Sensitivity
strcpy -- Copy Strings
stricmp -- Compare Strings as Lowercase
strncmp -- Compare Strings
strnicmp -- Compare Strings Without Case Sensitivity
strpbrk -- Find Characters in String
strrchr -- Find Last Occurrence of Character in String
strspn -- Search Strings
wcscmp -- Compare Wide-Character Strings
wcsncmp -- Compare Wide-Character Strings
<string.h>