home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / homonlib.zip / COUNTIN.BAS < prev    next >
BASIC Source File  |  1995-04-13  |  1KB  |  29 lines

  1. DEFINT A-Z
  2.  
  3. DECLARE FUNCTION CountIn (search$, lookfor$)
  4.  
  5. FUNCTION CountIn (search$, lookfor$)
  6. '****************************************************************************
  7. 'Returns the number of times that a substring is found within a string.
  8. '****************************************************************************
  9.  
  10. count = 0
  11.  
  12. IF search$ = "" OR lookfor$ = "" THEN             'Exit if searching in or
  13.      CountIn = count                              'looking for a null string.
  14.      EXIT FUNCTION
  15. END IF
  16.  
  17. x = INSTR(search$, lookfor$)                      'Find the first occurrence.
  18.  
  19. DO WHILE x > 0                                    'Go through the string,
  20.      count = count + 1                            'incrementing count and
  21.      last = x                                     'increasing the starting
  22.      x = INSTR((last + 1), search$, lookfor$)     'position each time the
  23. LOOP                                              'substring is found.
  24.  
  25. CountIn = count                                   'Return the count.
  26.  
  27. END FUNCTION
  28.  
  29.