Export (0) Print
Expand All
Expand Minimize
4 out of 5 rated this helpful - Rate this topic

strpbrk, wcspbrk, _mbspbrk

Scan strings for characters in specified character sets.

char *strpbrk(
   const char *string,
   const char *strCharSet 
);
wchar_t *wcspbrk(
   const wchar_t *string,
   const wchar_t *strCharSet 
);
unsigned char *_mbspbrk(
   const unsigned char*string,
   const unsigned char *strCharSet 
);

Parameters

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

Return Value

Returns a pointer to the first occurrence of any character from strCharSet in string, or a NULL pointer if the two string arguments have no characters in common.

Remarks

The strpbrk function returns a pointer to the first occurrence of a character in string that belongs to the set of characters in strCharSet. The search does not include the terminating null character.

wcspbrk and _mbspbrk are wide-character and multibyte-character versions of strpbrk. The arguments and return value of wcspbrk are wide-character strings; those of _mbspbrk are multibyte-character strings. These three functions behave identically otherwise. _mbspbrk is similar to _mbscspn except that _mbspbrk returns a pointer rather than a value of type size_t.

Generic-Text Routine Mappings

TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_tcspbrk strpbrk _mbspbrk wcspbrk

Requirements

Routine Required header Compatibility
strpbrk <string.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
wcspbrk <string.h> or <wchar.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
_mbspbrk <mbstring.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

// crt_strpbrk.c

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

int main( void )
{
   char string[100] = "The 3 men and 2 boys ate 5 pigs\n";
   char *result;
   /* Return pointer to first 'a' or 'b' in "string" */
   printf( "1: %s\n", string );
   result = strpbrk( string, "0123456789" );
   printf( "2: %s\n", result++ );
   result = strpbrk( result, "0123456789" );
   printf( "3: %s\n", result++ );
   result = strpbrk( result, "0123456789" );
   printf( "4: %s\n", result );
}

Output

1: The 3 men and 2 boys ate 5 pigs

2: 3 men and 2 boys ate 5 pigs

3: 2 boys ate 5 pigs

4: 5 pigs

See Also

String Manipulation Routines | strcspn | strchr | strrchr | Run-Time Routines and .NET Framework Equivalents

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.