home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / NOOCCUR.PRG < prev    next >
Text File  |  1991-08-16  |  3KB  |  81 lines

  1. /*
  2.  * File......: NoOccur.Prg
  3.  * Author....: David Husnian
  4.  * Date......: $Date:   15 Aug 1991 23:04:08  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/nooccur.prv  $
  7.  * 
  8.  * This is an original work by David Husnian and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/nooccur.prv  $
  15.  * 
  16.  *    Rev 1.2   15 Aug 1991 23:04:08   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.1   14 Jun 1991 19:52:32   GLENN
  20.  * Minor edit to file header
  21.  * 
  22.  *    Rev 1.0   01 Apr 1991 01:01:52   GLENN
  23.  * Nanforum Toolkit
  24.  *
  25.  */
  26.  
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_NOOCCUR()
  31.  *  $CATEGORY$
  32.  *     String
  33.  *  $ONELINER$
  34.  *     Find the number of times one string occurs in another
  35.  *  $SYNTAX$
  36.  *     FT_NOOCCUR( <cCheckFor>, <cCheckIn> ;
  37.  *                 [, <lIgnoreCase> ] )      -> <nOccurrences>
  38.  *  $ARGUMENTS$
  39.  *     <cCheckFor> is the string to search for
  40.  *
  41.  *     <cCheckIn> is the string to search
  42.  *
  43.  *     <lIgnoreCase> is a boolean variable to force case sensitivity
  44.  *     (optional, defaults to .F.).
  45.  *  $RETURNS$
  46.  *     The number of times <cCheckFor> appears in <cCheckIn>
  47.  *  $DESCRIPTION$
  48.  *     This function finds the number of times a string occurs in a
  49.  *        second string.
  50.  *  $EXAMPLES$
  51.  *     // Find the number of times "the" appears in cMemoString, case
  52.  *     // insensitive
  53.  *
  54.  *     nNoOfOccurrences := FT_NOOCCUR( "the", cMemoString )
  55.  *
  56.  *     // Find the number of times "the" appears in cMemoString, case
  57.  *     // sensitive
  58.  *
  59.  *     nNoOfOccurrences := FT_NOOCCUR( "the", cMemoString, TRUE )
  60.  *  $END$
  61.  */
  62.  
  63. #define IS_NOT_LOGICAL(x)            (VALTYPE(x) != "L")
  64. #define MAKE_UPPER(x)                (x := UPPER(x))
  65.  
  66. FUNCTION FT_NOOCCUR(cCheckFor, cCheckIn, lIgnoreCase)
  67.  
  68.                                         // Is Case Important??
  69.    IF (IS_NOT_LOGICAL(lIgnoreCase) .OR. lIgnoreCase)
  70.  
  71.       MAKE_UPPER(cCheckFor)             //  No, Force Everything to Uppercase
  72.       MAKE_UPPER(cCheckIn)
  73.  
  74.    ENDIF                                // IS_NOT_LOGICAL(lIgnoreCase) or ;
  75.                                         // lIgnoreCase
  76.  
  77.    RETURN (IF(LEN(cCheckFor) == 0 .OR. LEN(cCheckIn) == 0, ;
  78.               0, ;
  79.               INT((LEN(cCheckIn) - LEN(STRTRAN(cCheckIn, cCheckFor))) / ;
  80.                    LEN(cCheckFor))))
  81.