C library functions - strcspn ()
C standard library - <string.h>
description
C library functionssize_t strcspn (const char * str1, const char * str2) at the beginning of a continuous string str1retrieve a few characters do not contain the string of characters instr2.
statement
Here is strcspn () function's declaration.
size_t strcspn(const char *str1, const char *str2)
parameter
- str1 - C strings to be retrieved.
- str2 - the string contains a list of characters to be matched in the str1.
return value
This function returns the beginning of str1 does not contain the number of characters in a row are the characters in str2.
Examples
The following example demonstrates strcspn () function is used.
#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's compile and run the above program, which will result in the following:
第一个匹配的字符是在 10