Forum Navigation
You need to log in to create posts and topics.

[Q]srch&rplc: what is faster?

Posted by: chris_henkel <chris_henkel@...>

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