C Library Functions -strspn()
C Standard Library - <string.h>
Description
C Library Functionssize_t strspn(const char *str1, const char *str2)Search stringstr1the first character not in the stringstr2the index of the character appearing therein.
Declaration
The following is the declaration of the strspn() function.
size_t strspn(const char *str1, const char *str2)
Parameter
- str1-- The C string to be searched.
- str2-- The string containing the list of characters to match in str1.
Return Value
This function returns the index of the first character in str1 that does not appear in string str2.
Example
The following example demonstrates the usage of the strspn() function.
Example
#include <stdio.h>
#include <string.h>
int main ()
{
int len;
const char str1[] = "ABCDEFG019874";
const char str2[] = "ABCD";
len = strspn(str1, str2);
printf("Initial segment matching length %d\n", len );
return(0);
}
#include <string.h>
int main ()
{
int len;
const char str1[] = "ABCDEFG019874";
const char str2[] = "ABCD";
len = strspn(str1, str2);
printf("Initial segment matching length %d\n", len );
return(0);
}
Let us compile and run the above program, which will produce the following result:
初始段匹配长度 4other extensions