Partager via


strspn, wcsspn (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Find the first substring.

size_t strspn( const char *string, const char *strCharSet );size_t wcsspn( const wchar_t *string, const wchar_t *strCharSet);

Parameters

  • string
    Null-terminated string to search.
  • strCharSet
    Null-terminated character set.

Return Values

strspn and wcsspn 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.

Remarks

These functions are supported by all versions of the C run-time libraries.

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 is a wide-character version of strspn. The arguments of wcsspn are wide-character strings. These two functions behave identically otherwise.

The following table shows generic-text routine mappings for this function.

TCHAR.H Routine _UNICODE Defined
_tcsspn wcsspn

For more information about TCHAR.H routines, see Generic Text Mappings.

Example

Description

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.

Code

#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

Requirements

OS Versions: Windows CE 2.0 and later.

Header: stdio.h, string.h.

Link Library: coredll.dll.

See Also

strcspn | strncat | strncmp | strncpy

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.