span a string

You're viewing an older version of this page (#3503). View the current version.

View versions (4)

NAME

<span class="Nm" id="strspn">strspn</span>

INTERFACE

#include <string.h> size_t strspn ( const char *s, const char *charset )

DESCRIPTION

The strspn function spans the initial part of the null-terminated string &#92;c s as long as the characters from &#92;c s occur in string &#92;c charset.

Example 1

#include <stdio.h>
#include <string.h>

int main()
{
  char s[20] = "0123456abcde", t[11] = "0123456789";
  printf("The position of the first non-digit in s is: %d.\n", strspn(s, t));
  return 0;
}

Output:

The position of the first non-digit in s is: 7.

RETURN VALUES

The strspn function returns the number of characters spanned.

SEE ALSO

memchr, strchr, strcspn, strpbrk, strrchr, strstr, strtok

STANDARDS

The strspn function conforms to ISO/IEC 9899:1990 ("ISO C90").