STRCSPN - scan string for one or more characters.

(ANSI Standard)

Usage:

#include <string.h>
i = strcspn( s, stop );

Where:

const char *s;
points to the string to be scanned.
const char *stop;
points to a string containing the set of "stopping" characters.
size_t i;
gives the position of the first character from "stop" that appears in "s".

Description:

"strcspn" scans through "s" and finds the first character in "s" that also appears in "stop". It returns the position of that character within "s". Another way of saying this is that "strcspn" returns the number of characters at the beginning of "s" that are NOT found in "stop". For example,

j = strcspn(s," ");

determines how many characters occur before the first blank in "s".

The '\0' at the end of "stop" is considered to be part of "stop". Thus if "s" doesn't contain any of the other characters in "stop", "strcspn" will return the position of the '\0' at the end of "s" (which means that "strcspn" returns the length of "s").

Copyright © 1996, Thinkage Ltd.