Make your own free website on Tripod.com
 
 
 Tips & Trix
Find and Replace text in a String

Home
PUBz
Grafx Pax
Tips & Trix
Neo-Linx
Neo-Talk
NeoDezign Filez
Search NeoDezign
 
 
 

 


You can use the built-in functions of NeoBook to Find & Replace text within a String. It can be a bit tricky but with some careful scripting it can be done. 

Normally, you would use SearchStr to scan a string. The trick is to use SubStr instead. By increment these postions forward at the same time while reading the space between the postions with each increment.

In this example I am going to scan the following [textstring]... 

"NeoBook allows just about anyone to produce royalty-free..."

...[find] "just about anyone"...

...and I am going to [replace] it with "absolutley everyone"!
 

First, I begin by determining the length of the string that I want to find...

"just about anyone" is 17 characters long. Store this LEN in [findlen]

Next, "prime the pump" for a While loop SetVar "[a]" "1"

Begin scanning across [textstring] using SubStr 
the 1st postion is [a]
the last postion is [findlen]

Action Script:

SetVar "[a]" "1"
StrLen "[textstring]" "[textlen]"
StrLen "[find]" "[findlen]"

While "[a]" "<=" "[textlen]"
SubStr "[textstring]" "[a]" "[findlen]" "[scan]"

If "[find]" "=" "[scan]"
StrDel "[textstring]" "[a]" "[findlen]" "[textstring]"
StrIns "[replace]" "[textstring]" "[a]" "[textstring]"
GotoLine "END"
EndIf

Math "[a]+1" "" "[a]"

EndWhile

:END
AlertBox "" "[textstring]"
 
 





















A

...