strspn
size_t strspn ( const char * string1, const char * string2 ); | string.h |
cplusplus.com |
Get length of substring composed of given characters.
Scans string1 character by character, returning the number of characters read
before the first character not included in string2 is found.
The search does not include terminating null-characters.
Parameters.
Return Value.
Returns the length of the initial substring of string1 that
is only composed of characters included in string2.
Portability.
Defined in ANSI-C.
Example.
/* strspn example */
#include <stdio.h>
#include <string.h>
main ()
{
int i;
char strtext[] = "129th";
char cset[] = "1234567890";
i = strspn (strtext,cset);
printf ("Length of initial number is %d\n",i);
return 0;
}
Output:
Length of initial number is 3
See also.
strcspn,
strstr,
strchr,
strrchr