strcspn, wcscspn (Windows CE 5.0)

Send Feedback

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

Find a substring in a string.

size_t strcspn( const char *string, const char *strCharSet);size_t wcscspn( const wchar_t *string, const wchar_t *strCharSet);

Parameters

  • string
    Null-terminated searched string.
  • strCharSet
    Null-terminated character set.

Return Values

Each of these functions returns an integer value specifying the length of the initial segment of string that consists entirely of characters not in strCharSet. If string begins with a character that is 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 strcspn function returns the index of the first occurrence of a character in string that belongs to the set of characters in strCharSet. Terminating null characters are included in the search.

wcscspn is the wide-character version of strcspn. The arguments of wcscspn 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
_tcscspn wcscspn

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

Example

Description

The following example finds substrings in a string.

Code

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

void main( void )
{
   char string[] = "xyzabc";
   int  pos;

   pos = strcspn( string, "abc" );
   printf( "First a, b or c in %s is at character %d\n", 
           string, pos );
}
// Output
First a, b or c in xyzabc is at character 3

Requirements

OS Versions: Windows CE 2.0 and later.

Header: stdio.h, string.h.

Link Library: coredll.dll.

See Also

strncat | strncmp | strncpy

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.