C Library Function - strcspn()
Description
C Library Function **size_t strcspn(const char *str1, const char *str2) ** retrieves the string str1 how many consecutive characters at the beginning do not contain the string str2 characters in .
Declaration
Below is the declaration of the strcspn() function.
size_t strcspn(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 number of consecutive characters at the beginning of str1 that do not contain characters from the string str2.
Example
The following example demonstrates the use of the strcspn() function.
#include
#include
int main ()
{
int len;
const char str1[] = "ABCDEF4960910";
const char str2[] = "013";
len = strcspn(str1, str2);
printf("第一个匹配的字符是在 %d\n", len + 1);
return(0);
}
Let's compile and run the above program, which will produce the following result:
第一个匹配的字符是在 10
C Standard Library -