Standards / Extensions | C or C++ | Dependencies |
---|---|---|
Language Environment |
both |
#include <string.h>
size_t strspn(const char *string1, const char *string2);
Calculates the length of the maximum initial portion of the string pointed to by string1 that consists entirely of the characters contained in the string pointed to by string2.
strspn() returns the length of the substring found.
⁄* CELEBS50
This example finds the first occurrence in the array string
of a character that is neither an a, b, nor 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 );
}
The first 5 characters of "cabbage" are found in "abc"