home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / occurs.prg < prev    next >
Text File  |  1993-10-14  |  2KB  |  76 lines

  1. /*
  2.  * File......: OCCURS.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_OCCURS()
  24.  *  $CATEGORY$
  25.  *      String
  26.  *  $ONELINER$
  27.  *      Count the number of occurences of a character in a string
  28.  *  $SYNTAX$
  29.  *      GT_Occurs( cChar , cString )
  30.  *  $ARGUMENTS$
  31.  *      cChar   - Character to find
  32.  *      cString - String to search
  33.  *  $RETURNS$
  34.  *      The number of occurences
  35.  *  $DESCRIPTION$
  36.  *      Count the number of occurences of a character in a string
  37.  *  $EXAMPLES$
  38.  *
  39.  *  $SEEALSO$
  40.  *
  41.  *  $INCLUDE$
  42.  *      GT_LIB.CH
  43.  *  $END$
  44.  */
  45.  
  46. *
  47. #include "GT_LIB.ch"
  48.  
  49. FUNCTION GT_Occurs( cChar , cString )
  50.  
  51. /****************************************************************************
  52.  Purpose - Count number of occurences of cChar in cString
  53.  Returns - Number of occurences
  54.  Author  - Martin Colloby
  55.  Created - 8/1/91
  56. ******************************************************************************
  57.  Parameters - cChar   - Character to find
  58.               cString - String to search
  59.  Privates   - nCount  - Counting variable
  60.               nCount1 - Counting variable
  61.  Externals  - None
  62. ****************************************************************************/
  63.  
  64. LOCAL nCount  := 0
  65. LOCAL nCount1 := 0
  66.  
  67. FOR nCount1 := 1 TO len( cString )
  68.     IF SUBSTR( cString , nCount1 , 1 ) == cChar
  69.         nCount ++
  70.     ENDIF
  71. NEXT nCount
  72.  
  73. * Return the count
  74. RETURN( nCount )
  75. *
  76.