Use C strcspn function to find the index of a sub string
Syntax
C strcspn function has the following format.
size_t strcspn(const char *str1, const char *str2);
Header
C strcspn function
is from header file string.h
.
Description
C strcspn function
returns the index of the first character in
*str1
that matches any of the characters in *str2
.
Example
Use C strcspn function to find the index of a sub string.
#include <string.h>
#include <stdio.h>
/*from w w w. ja v a 2 s . c o m*/
int main(void)
{
int len;
len = strcspn("this is a test", "ab");
printf("%d", len);
return 0;
}
The code above generates the following result.