strspn, wcsspn, _mbsspn

Find the first substring.

size_tstrspn(constchar*string,constchar*strCharSet);

size_twcsspn(constwchar_t*string,constwchar_t*strCharSet);

size_t_mbsspn(constunsignedchar*string,constunsignedchar*strCharSet);

Routine Required Header Compatibility
strspn <string.h> ANSI, Win 95, Win NT
wcsspn <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbsspn <mbstring.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

strspn, wcsspn, and _mbsspn return an integer value specifying the length of the substring in string that consists entirely of characters in strCharSet. If string begins with a character not in strCharSet, the function returns 0. No return value is reserved to indicate an error. For each of these routines, no return value is reserved to indicate an error.

Parameters

string

Null-terminated string to search

strCharSet

Null-terminated character set

Remarks

The strspn function returns the index of the first character in string that does not belong to the set of characters in strCharSet. The search does not include terminating null characters.

wcsspn and _mbsspn are wide-character and multibyte-character versions of strspn. The arguments of wcsspn are wide-character strings; those of _mbsspn are multibyte-character strings. These three functions behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcsspn strspn _mbsspn wcsspn

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

String Manipulation Routines

See Also   _mbsspnp,strcspn, strncat, strncmp, strncpy, _strnicmp, strrchr