strcspn
Computes the length of the initial segment of a string consisting of characters not from a given set
#include <string.h> size_t strcspn ( const char *str, const char *charset);
The strcspn function returns the offset position in a string where the first occurrence of charset begins.
The strcspn function computes the length of the initial segment of the string pointed to by str, which consists entirely of characters not from the string pointed to by charset. The terminating NULL character is not considered part of str.
#include <string.h> main () { printf ("%d\n", strcspn ("abcbcadef", "cba") ); printf ("%d\n", strcspn ("xxxbcadef", "cba") ); printf ("%d\n", strcspn ("123456789", "cba") ); }
produces the following:
0 3 9