### strspn -- Search Strings

Format

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

Language Level: ANSI, POSIX, XPG4
strspn finds the first occurrence of a character in string1 that is not contained in the set of characters specified by string2. The null character (\0) that ends string2 is not considered in the matching process.

Return Value
strspn returns the index of the first character found. This value is equal to the length of the initial substring of string1 that consists entirely of characters from string2. If string1 begins with a character not in string2, strspn returns 0. If all the characters in string1 are found in string2, the length of string1 is returned.

Example
This example finds the first occurrence in the array string of a character that is not an a, b, or c. Because the string in this example is cabbage, strspn returns 5, the length of the segment of cabbage before a character that is not an a, b, or c.

    #include <stdio.h>
    #include <string.h>

    int main(void)
    {
      char * string = "cabbage";
      char * source = "abc";
      int index;

      index = strspn( string, "abc" );
      printf( "The first %d characters of \"%s\" are found in \"%s\"\n",
              index, string, source );
      return 0;

      /****************************************************************
         The output should be:

         The first five characters of "cabbage" are found in "abc"
      ****************************************************************/
    }

strcat -- Concatenate Strings
strchr -- Search for Character
strcmp -- Compare Strings
strcpy -- Copy Strings
strcspn -- Compare Strings for Substrings
strpbrk -- Find Characters in String
strrchr -- Find Last Occurrence of Character in String
wcschr -- Search for Wide Character
wcscspn -- Find Offset of First Wide-Character Match
wcspbrk -- Locate Wide Characters in String
wcsrchr -- Locate Wide Character in String
wcsspn -- Search Wide-Character Strings
wcswcs -- Locate Wide-Character Substring
<string.h>