home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / isrun01.zip / stristr.h < prev   
C/C++ Source or Header  |  1997-10-12  |  1KB  |  57 lines

  1. /*************************************************************************
  2.  
  3.                   Case insensitive version of strstr
  4.                   ----------------------------------
  5.  
  6.  
  7.                  by Stephane Bessette (stephb7@usa.net)
  8.                              Freeware @1997
  9.  
  10.  
  11.  
  12. BOOL stristr( char *string, char *substring)
  13.  
  14.  
  15.                                  Example
  16.                                  -------
  17.  
  18. char string[] = "This is a string";
  19. char substring[] = "IS a";
  20.  
  21. if( stristr( string, substring ) )
  22.      // The substring is contained in the string
  23. else
  24.      // The substring is not contained in the string
  25.  
  26. *************************************************************************/
  27.  
  28. #ifndef STRISTR_H
  29. #define STRISTR_H
  30.  
  31. #include <ctype.h>
  32.  
  33. BOOL stristr( char *string, char *substring )
  34. {
  35.      // A case insensitive version of strstr
  36.  
  37.      while( *string && tolower( *substring ) != tolower( *string ) )
  38.      {
  39.           string++;
  40.      }
  41.      if( *string )
  42.      {
  43.           // The beginning of the substring was found in the string
  44.           while( *string && *substring && tolower( *substring ) == tolower( *string ) )
  45.           {
  46.                string++;
  47.                substring++;
  48.           }
  49.           if( !*substring )
  50.                // The whole substring was located
  51.                return TRUE;
  52.      }
  53.      return FALSE;
  54. }
  55.  
  56. #endif // STRISTR_H
  57.