strspn()                 Find First Substring
 
 #include   <string.h>                   Required for declarations only
 
 int        strspn(string1,string2);
 char       *string1;                    Searched string
 char       *string2;                    Character set
 
    strspn() tests whether the first substring (i.e., the substring
    beginning at the start of 'string1') in 'string1' consists entirely
    of characters from character set 'string2'.  (It does this by
    searching 'string1' for the first occurrence of a character that is
    not also in 'string2'.)
 
    Returns:    The index in 'string1' of the first character past the
                substring that contains only characters from 'string2'.
                This is equal to the first character in 'string1' that is
                not among the characters in 'string2'.  Looking at it
                another way, the index value is equal to the length of
                the substring of 'string1' that is made up of characters
                from 'string2'.
 
  -------------------------------- Example ---------------------------------
 
    The following statements check whether 'string' begins with a vowel.
 
         #include <string.h>
 
         int rslt;
         char *string = "imagination";
         char *charset = "aeiou";
 
         main()
         {
             if((rslt = strspn(string,charset)) > 0)
                      printf("string begins with a vowel\n");
         }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster