Replace command

Alex Tweedly alex at
Sat Apr 10 19:30:52 EDT 2010

David Coker wrote:
> There seems to be an easy consensus, so that's the direction I'll take
> my code...
> Up until now I have never attempted using the wordOffset function for
> the small things I've been building with Rev, so I guess it's time to
> work it into my coding routines for the future.
> Thank you folks so much for the advice and samples!
Be a little bit careful here ....

the original script you posted (i.e. using replace) will replace the 
string "Piper" with "Jones" - regardless of whether it is an entire word 
on its own or not.
so "abc Piper def" would become "abc Jones def", but also "abc 
ghiPiperjkl def" would become "abc ghiJonesjkl def".

However, using wordoffset as described here will replace the entire 
word, so "abc ghiPiperjkl def" would become "abc jones def" !!

If you only want to replace Piper when it is the entire word, you can 
set  wholeMatches (q.v.) true to get around this.

If not, then you might instead do
   put offset("Piper", tContainer) into tStart
   put "Jones" into char tStart to tStart+4 of tContainer

-- Alex.
   put "Jones" into char (charoffset

More information about the Use-livecode mailing list