Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <b>strspn() find first substring</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
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");
         }

See Also: strcspn() strstr()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson