strspn, _fstrspn

Description

Find the first substring.

#include <string.h> Required only for function declarations  

size_t strspn( const char *string1, const char *string2 );

size_t __far _fstrspn( const char __far *string1, const char __far *string2 );

string1 Searched string  
string2 Character set  

Remarks

The strspn function returns the index of the first character in string1 that does not belong to the set of characters specified by string2. This value is equivalent to the length of the initial substring of string1 that consists entirely of characters from string2. The null character ('\0') terminating string2 is not considered in the matching process. If string1 begins with a character not in string2, strspn returns 0.

The _fstrspn function is a model-independent (large-model) form of the strspn function. The behavior and return value of _fstrspn are identical to those of the model-dependent function strspn, with the exception that the arguments are far pointers.

Return Value

These functions return an integer value specifying the length of the segment in string1 consisting entirely of characters in string2.

Compatibility

strspn

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

_fstrspn

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

strcspn, strncat, strncmp, strncpy, _strnicmp, strrchr

Example

/* STRSPN.C: This program uses strspn to determine the length of

* the segment in the string "cabbage" consisting of a's, b's, and c's.

* In other words, it finds the first non-abc letter.

*/

#include <string.h>

#include <stdio.h>

void main( void )

{

char string[] = "cabbage";

int result;

result = strspn( string, "abc" );

printf( "The portion of '%s' containing only a, b, or c "

"is %d bytes long\n", string, result );

}

Output

The portion of 'cabbage' containing only a, b, or c is 5 bytes long