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

  1. DEFINT A-Z
  2.  
  3. DECLARE FUNCTION Stuff$ (orig$, position, delnum, char$)
  4.  
  5. FUNCTION Stuff$ (orig$, position, delnum, char$)
  6. '****************************************************************************
  7. 'Inserts and/or deletes character(s) in(to) a string at the specified
  8. ' character position.  Very simple, but very useful.
  9. '
  10. 'The position argument tells the function where to start its operations upon
  11. ' the original.
  12. '
  13. 'The delnum argument tells it how many (if any) characters to delete starting
  14. ' at that position.
  15. '
  16. 'The value of char$ determines what gets put into the string at position.  If
  17. ' null, nothing will get put in, effectively deleting characters from within
  18. ' the string.
  19. '
  20. 'Examples: Stuff$("QBasic",2,0,"uick") --> "QuickBasic" (Adds characters)
  21. '          Stuff$("Landlocked",5,4,"") --> "Landed"     (Deletes characters)
  22. '          Stuff$("Trifle",4,1,"bb")   --> "Tribble"    (Replaces characters)
  23. '
  24. 'Specifying a delnum of zero and a null char$ will do nothing.
  25. '
  26. '****************************************************************************
  27.  
  28. part1$ = LEFT$(orig$, position - 1)     'Break the string into two parts at
  29. part2$ = MID$(orig$, position + delnum) 'the specified position, skipping any
  30.                                         'characters to be deleted.
  31.  
  32. Stuff$ = part1$ + char$ + part2$        'Rebuild the string, including char$
  33.                                         'between the two parts.
  34. END FUNCTION
  35.  
  36.