Genii Weblog

Method of the Day: ReplaceText

Thu 8 Sep 2005, 06:54 AM



by Ben Langhinrichs
When I posted Method of the Day: AppendHotspot, people responded with surprise that one method could be good for so much.  I thought that it would be good to show another mild mannered method which becomes a supermethod when you fully understand it, the ReplaceText method.

It may be hard to imagine just what the ReplaceText  method might do besides replace text, but that is why I am writing this.  To follow the format from the last post, here are recent questions for which the answer is the ReplaceText method.

Q. Can I search for a string in a rich text field and replace it with another without hurting the format of the surrounding text and without losing images and tables?
A. Sure.  Just use code such as:
Call rtitem.ConnectBackend(doc.Handle, "Body")
Set rtchunk = rtitem.DefineChunk("Everything")
Call rtchunk.ReplaceText(searchstring, replacestring)

Q. Can I search for a wildcard string in a rich text field and replace it?
A. Sure.  Just use code such as:
Call rtitem.ConnectBackend(doc.Handle, "Body")
Set rtchunk = rtitem.DefineChunk("Everything")
rtchunk.TextWildCards = True
searchstring = "SRN*001"
replacestring = "OBSOLETE PRODUCT NUMBER"
Call rtchunk.ReplaceText(searchstring, replacestring)

Q. Can I change the URL inside a URL hotspot?
A. Sure.  Just use code such as:
Call rtitem.ConnectBackend(doc.Handle, "Body")
Set rtchunk = rtitem.DefineChunk("Everything")
Call rtchunk.ReplaceText("www.notes.net", "http://www-130.ibm.com/developerworks/lotus""URL")

Also see the new Replace URLs sample db on the Midas Rich Text LSX sample dbs page.  

Q. Can I change hide-when formulas with Midas?
A. Sure.  Just use code such as:
Call rtitem.ConnectBackend(doc.Handle, "Body")
Set rtchunk = rtitem.DefineChunk("Everything")
Call rtchunk.ReplaceText("@UserName", "@V2UserName""HideWhen")

Watch for the new Hide-When sample sample db coming soon to the Midas Rich Text LSX sample dbs page.  

Q. Can I change section titles?
A. Sure.  Just use code such as:
Call rtitem.ConnectBackend(doc.Handle, "Body")
Set rtchunk = rtitem.DefineChunk("Everything")
Call rtchunk.ReplaceText("Sumary", "Summary""NonText")


Q. Can I change action hotspots?
A. Sure.  Just use code such as:
Call rtitem.ConnectBackend(doc.Handle, "Body")
Set rtchunk = rtitem.DefineChunk("ActionHotspot *")
Call rtchunk.ReplaceText("@UserName", "@V2UserName""Formula")


URLs in hotspots?  Formulas in action hotspots?  Hide-when formulas?  Pretty powerful for search and replace, don't you think?

Copyright © 2005 Genii Software Ltd.

What has been said:


364.1. Mike Kyslinger
(09/11/2005 02:36 PM)

I would buy this T-shirt.