My point was to be careful of using (wordOffset + replace) because

put wordOffset("happy", textBlockOfLines) into wordPosition
replace word wordPosition of textBlockOfLines with "sad"

can give undesired results such as-----

feel happy and safe
feel sad and safe -- OK

It is good to feel happy, yet afraid
It is good to feel sad yet afraid -- no comma

Feel happy.  Be careful.
Feel sad  Be careful.  -- no period

Punctuation is one of the unintended casualties of wordOffset.

Jim Ault
Las Vegas



On Apr 10, 2010, at 1:34 PM, Peter Brigham MD wrote:

Right, "replace" is the thing to use for a global replace task, but if you are doing a more sophisticated search/replace -- checking context of various matches and narrowing the search further -- the multiple offsets function is quite useful. Also, I need on occasion to find the *last* occurrence of a string in a container, and "item -1 of offsets(tString,tContainer)" is great for this.

-- Peter

Peter M. Brigham
On Apr 10, 2010, at 2:51 PM, Mark Schonewille wrote:

Peter,

As David pointed out, you can do that easily with the replace command. I thought I'll mention this to avoid confusion.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer

Share the clipboard of your computer with other computers on a local network with Clipboard Link
http://clipbaordlink.economy-x-talk.com

Op 10 apr 2010, om 20:28 heeft Peter Brigham MD het volgende geschreven:

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

_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to