[comp.sys.handhelds] More search and replace

apdoo@alice.UUCP (Alan Weiss) (03/23/90)

Just a followup on the search and replace function
I posted a day ago...typing in the program, I noticed that
the use of MULTI could be eliminated and the program would
be faster.  So I did it.  Here is the new search and replace
function, with new timing info:

Benchmarks: CHR 0 to "V" in a STR-> string: his 92 sec, mine 80 sec,now 76 sec
            Replace a string of 10 "Z" characters with 10 "U" chars:
                                          his 1.6 sec, mine .97 sec,now .71 sec
The new and old substrings do not have to be the same length; indeed,
the biggest use I have for this program is stripping out newline
characters and replacing them with empty strings.

CHG2 [checksum 5AFC]
3: String to change
2: Old substring      ----->
1: New substring              1:Changed string

<< -> x y
  <<
     WHILE DUP x POS
DUP
     REPEAT DUP2 1 -
1 SWAP SUB 3 ROLLD 1
+ OVER SIZE SUB y
SWAP + +
     END DROP
  >>
>>


Alan Weiss, AT&T Bell Labs    inet!research.att.com!apdoo