Replace command

Jim Ault jimaultwins at yahoo.com
Sat Apr 10 14:46:20 EDT 2010


This kind of search and replace has been discussed before, about 3  
months ago on this list.

Caveats are the definition of a word in Rev vs a programmer's or  
user's definition.
Commas can be part of a word
    a,word,seen,as,one  two words,
Also be careful of the wordOffset hit rules.  It may not be exactly  
what you think when you consider paragraphs, punctuation, and data  
tables with delimiters.

There are some other gotchas that need to be rigorously tested.

Jim Ault
Las Vegas


On Apr 10, 2010, at 11:28 AM, Peter Brigham MD wrote:

> On Apr 10, 2010, at 11:52 AM, David Coker wrote:
>
>> Mark wrote:
>>> put "Jones" into word wordOffset("Piper",tContainer) of tContainer
>>
>> then Michael added:
>>
>>> put
>>>
>>> Peter Piper picked
>>> If Peter Piper picked again
>>>
>>> into fld 1
>>> -----------------------------
>>> -- use this script
>>> -----------------------------
>>> on mouseUp
>>> put wordOffset("Peter",fld 1) into x
>>> put "Jones" into word x of fld 1
>>> end mouseUp
>>> ----------------------
>>
>> 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!
>>
>> Best regards,
>> David C.
>
> The code above will find and replace the first occurrence of the  
> string. For access to all the occurrences, use this handler:
>
> function offsets str,cntr
>  -- returns a comma-delimited list
>  -- of all the offsets of str in cntr
>  if str is not in cntr then return 0
>  put "" into offsetList
>  put 0 into startPoint
>  repeat
>     put offset(str,cntr,startPoint) into thisOffset
>     if thisOffset = 0 then exit repeat
>     add thisOffset to startPoint
>     put startPoint & comma after offsetList
>  end repeat
>  delete last char of offsetList
>  return offsetList
> end offsets
>
> -- Peter
>
> Peter M. Brigham
> pmbrig at gmail.com
> http://home.comcast.net/~pmbrig




More information about the use-livecode mailing list