C Library Function - strspn()
Description
C Library Function **size_t strspn(const char str1, const char str2) Search the string str1 for the first character that is not in the string str2 the index of the character that appears.
Declaration
Below is the declaration of the strspn() function.
size_t strspn(const char *str1, const char *str2)
Parameters
- str1 -- the C string to be searched.
- str2 -- this string contains 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 the string str2.
Example
The following example demonstrates the use of the strspn() function.
Example
#include
#include
int
main
(
)
{
int
len
;
const
char
str1
[
]
=
"ABCDEFG019874"
;
const
char
str2
[
]
=
"ABCD"
;
len
=
strspn
(
str1
,
str2
)
;
printf
(
"Initial segment match length %d\n"
,
len
)
;
return
(
0
)
;
}
Let's compile and run the above program, which will produce the following result:
初始段匹配长度 4
C Standard Library -