size_t strspn ( const char * str1, const char * str2 );
Get span of character set in string
Returns the length of the initial portion of str1 which consists only of characters that are part of str2.
The search does not include the terminating null-characters of either strings, but ends there.
- C string to be scanned.
- C string containing the characters to match.
The length of the initial portion of str1 containing only characters that appear in str2.
Therefore, if all of the characters in str1 are in str2, the function returns the length of the entire str1 string, and if the first character in str1 is not in str2, the function returns zero.
size_t is an unsigned integral type.
/* strspn example */
int main ()
char strtext = "129th";
char cset = "1234567890";
i = strspn (strtext,cset);
printf ("The initial number has %d digits.\n",i);
The initial number has 3 digits.
- Get span until character in string (function
- Locate substring (function
- Compare characters of two strings (function