次の方法で共有


strpbrk, wcspbrk, _mbspbrk

Scan strings for characters in specified character sets.

char*strpbrk(constchar*string,constchar*strCharSet);

wchar_t*wcspbrk(constwchar_t*string,constwchar_t*strCharSet);

unsignedchar*_mbspbrk(constunsignedchar*string,constunsignedchar*strCharSet);

Routine Required Header Compatibility
strpbrk <string.h> ANSI, Win 95, Win NT
wcspbrk <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbspbrk <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

Each of these functions 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.

Parameters

string

Null-terminated, searched string

strCharSet

Null-terminated character set

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

Example

/* STRPBRK.C */

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

void 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

String Manipulation Routines

See Also   strcspn, strchr, strrchr