cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cstring (string.h) : strspn
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstring (string.h)
functions:
· memchr
· memcmp
· memcpy
· memmove
· memset
· strcat
· strchr
· strcmp
· strcoll
· strcpy
· strcspn
· strerror
· strlen
· strncat
· strncmp
· strncpy
· strpbrk
· strrchr
· strspn
· strstr
· strtok
· strxfrm
macros:
· NULL
types:
· size_t

-

strspn function
size_t strspn ( const char * str1, const char * str2 );
<cstring>

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.

Parameters

str1
C string to be scanned.
str2
C string containing the characters to match.

Return value

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.

Example

/* strspn example */
#include <stdio.h>
#include <string.h>

int main ()
{
  int i;
  char strtext[] = "129th";
  char cset[] = "1234567890";

  i = strspn (strtext,cset);
  printf ("The length of initial number is %d.\n",i);
  return 0;
}

Output:


The length of initial number is 3.

See also

strcspn Get span until character in string (function)
strstr Locate substring (function)
strncmp Compare characters of two strings (function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us