Find a substring in a string.
#include <string.h> | Required only for function declarations |
size_t strcspn( const char *string1, const char *string2 );
size_t __far _fstrcspn( const char __far *string1, const char __far *string2 );
string1 | Source string | |
string2 | Character set |
The strcspn functions return the index of the first character in string1 belonging to the set of characters specified by string2. This value is equivalent to the length of the initial substring of string1 consisting entirely of characters not in string2. Terminating null characters are not considered in the search. If string1 begins with a character from string2, strcspn returns 0.
The strcspn and _fstrcspn functions operate on null-terminated strings. The string arguments to these functions are expected to contain a null character ('\0') marking the end of the string.
The _fstrcspn function is a model-independent (large-model) form of the strcspn function. The behavior and return value of _fstrcspn are identical to those of the model-dependent function strcspn, with the exception that the arguments and return values are far.
The return values for these functions are described above.
strcspn
Standards:ANSI, UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
_fstrcspn
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
strncat, strncmp, strncpy, _strnicmp, strrchr, strspn
/* STRCSPN.C */
#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 );
}
First a, b or c in xyzabc is at character 3