[futurebasic] [Q]srch&rplc: what is faster?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 1997 : Group Archive : Group : All Groups

From: chris_henkel@... (Chris Henkel)
Date: Tue, 25 Nov 1997 00:35:54 +0200
Hello.

What I have: textfiles with a size of about 64KB (most of the time less). In
these files are some characters (about 130 different chars) which I want to
replace with an expression.

At this time I do it like (not actual FB-code!)

x = -1
 do
     x = x + 1
     srch$ = CHR$(x)
     rplc$ = HEX$(x)
     osErr& = FN MUNGE(srch$,rplc$)
       -> FN MUNGE looks for srch$ in txthndl& until
       -> all srch$ are replaced by rplc$
  until x >= 255

That means, my code will call the munge-function at least 256 times to look for
srch$ and then call the replace-function every time it finds srch$. In practice
this seems to be slow.

Would the following be faster?

x = 0
  do
     x = x + 1
     srch$ = char x of txthndl& (with PEEK for example)
     SELECT srch$
          CASE srch$ = charImLookingFor$
               osErr& = FN MUNGE
                 -> FN MUNGE looks for srch$ in txthndl& until
                 -> all srch$ are replaced by rplc$
     END SELECT
  until x = size(txthndl&)

If I did not explain clear enough what my intentions are, please ask and I will
try to express myself with more 'words'.

Thank you for taking the time to think about it.

chris


this message was sent from the ChatWorks BBS

FirstClass-TCP-access: bbs.chatworks.de, port 3004
Commandline-TCP-access: bbs.chatworks.de, port 23