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

  1. DEFINT A-Z
  2.  
  3. DECLARE FUNCTION Squeeze$ (orig$, char$)
  4.  
  5. FUNCTION Squeeze$ (orig$, char$)
  6. '****************************************************************************
  7. 'Removes all occurrences of a substring from within a string.
  8. '
  9. 'Example: Squeeze$("Peter Piper","er") --> "Pet Pip"
  10. '
  11. '****************************************************************************
  12.  
  13. IF orig$ = "" OR char$ = "" THEN        'If either argument is a null string,
  14.      Squeeze$ = orig$                   'return the original because nothing
  15.      EXIT FUNCTION                      'can be squeezed from a null string
  16. END IF                                  'and INSTR always returns 1 when
  17.                                         'searching for a null string.
  18.  
  19. new$ = orig$                            'Don't alter the original in case the
  20.                                         'calling program still needs it!
  21.  
  22. DO WHILE INSTR(new$, char$) > 0         'Loop until char$ is no longer found.
  23.   
  24.      x = INSTR(new$, char$)             'Find the location of char$.
  25.      l$ = LEFT$(new$, x - 1)            'Get the part to the left of char$.
  26.      r$ = MID$(new$, x + LEN(char$))    'Get the part to the right of char$.
  27.      new$ = l$ + r$                     'Put the string back together without
  28.                                         'char$!
  29. LOOP
  30.  
  31. Squeeze$ = new$                         'Return the squeezed string
  32.  
  33. END FUNCTION
  34.  
  35.