C Library Functions -strcspn()
C Standard Library - <string.h>
Description
C Library Functionssize_t strcspn(const char *str1, const char *str2) Search stringstr1Several consecutive characters at the beginning do not contain the string.str2characters in.
Declaration
Below is the declaration of the strcspn() function.
size_t strcspn(const char *str1, const char *str2)
Parameter
- str1-- The C string to be searched.
- str2-- This string contains a list of characters to be matched in str1.
Return Value
This function returns the number of consecutive characters at the beginning of str1 that do not contain any characters from str2.
Example
The following example demonstrates the usage of the strcspn() function.
#include <stdio.h>
#include <string.h>
int main ()
{
int len;
const char str1[] = "ABCDEF4960910";
const char str2[] = "013";
len = strcspn(str1, str2);
printf("第一个匹配的字符是在 %d\n", len + 1);
return(0);
}
Let us compile and run the above program, which will produce the following result:
第一个匹配的字符是在 10other extensions