Ben Langhinrichs

Photograph of Ben Langhinrichs

E-mail address - Ben Langhinrichs







Recent posts

Thu 10 Jun 2021

Notes 12 without all the blue



Wed 5 May 2021

Pull public data into Notes on the fly



Thu 29 Apr 2021

Archive a Notes DB off-line w/ Field data and active content


August, 2021
SMTWTFS
01 02 03 04 05 06 07
08 09 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

Search the weblog





























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.