strcspn() Scan One String for Another
#include <string.h> Required for declarations only
unsigned int strcspn(string1,charset);
char *string1; Source string
char *charset; Character set
strcspn() searches 'string1' for the first occurrence of any of the
characters in 'charset'. The null character which terminates the
string is not considered in the search.
Returns: The index of the first character in 'string1' that
belongs to the set of characters found in 'charset'.
This value equals the length of the first substring of
'string1' that is made up of characters not in 'charset'.
If 'string1' begins with a character in 'string2',
strcspn() returns 0.
Notes: strcspn() expects to operate on null-terminated strings.
No overflow checking is done when strings are copied or
appended.
-------------------------------- Example ---------------------------------
This example gets the length of the string up to the first delimiter
defined in the string 'delim'.
#include <string.h>
char string[35] = "Pick up the sword. Run for cover.";
char delim[3] = ".!?";
int rslt;
main()
{
rslt = strcspn(string,delim);
printf("%c \n",string[rslt]);
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster