Solved

Replacing substrings in a RichText field - possible??

Posted on 2002-07-26
9
632 Views
Last Modified: 2013-12-18
Is it possible somehow - and if it is, do you know HOW - to replace a substring in a RichText field in a document?

Thanks a lot for any solution!!!

~adams
0
Comment
Question by:adamsfamily
9 Comments
 
LVL 9

Expert Comment

by:Arunkumar
ID: 7179779
Did you try to use the @Abstract on the RTField and then do the @ReplaceSubstring and then @SetField to set the RTField with the new value ???

-Arun

0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7180584
This routine does the job, but loses all the nice rt format.

Sub Click(Source As Button)
     Dim session As New NotesSession
     Dim ws As New NotesUIWOrkspace
     Dim uidoc As NotesUIDOcument
     Dim note As NotesDocument
     Dim rt As NotesRichTextItem
     
     Set uidoc = ws.CurrentDocument
     Set note = uidoc.DOcument
     Set rt = note.GetFirstItem( "RT" )
     ret = ReplaceSubstring( rt.text, "notes", "Domino")
     Call rt.Remove
     Set rt = note.CreateRichTextItem( "RT" )
     Call rt.AppendText( ret )
     note.save True, False
End Sub


Function ReplaceSubstring( Byval s1 As String, s2 As String, s3 As String) As Variant
     Dim index%
     
     index = Instr( s1, s2 )
     If index = 0 Then
          ReplaceSubstring = s1
     Else
          ReplaceSubstring = Left$(s1, index - 1 ) & s3 & ReplaceSubstring(Right$(s1, Len(s1) - (index + Len(s2)) + 1 ), s2, s3 )
     End If
End Function


~Hemanth
0
 
LVL 3

Expert Comment

by:Joep8020
ID: 7185125
There is an article in The View from July/August 1998, dealing with using the C API to manipulate RTF.

This is an excellent resource to understand how to do what you want. By the way, you can also change colors, fonts etc. using these methods.

good luck
0
 

Author Comment

by:adamsfamily
ID: 7201172
Dear Hemanth,

  thanks for the code you wrote, the problem is that I would have liked to use templates for documents, that a user can edit in a rich text, and additionally he can add special strings ("fields") into the richtext and an agent should replace them with their actual value :-(
  So the formatted RichText would have been the basic of the solution. But thanks anyway.

Joep8020,

  I was afraid to use C API because of the compatibility with various Notes clients, windows versions, etc. But I'm going to have a look at it. Thanks

~adams
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7203613
Then Sorry!!! there is no other way to handle text in richtext field.

C API, could be a solution, but it is little tedious to understand it at first ?!?
0
 

Author Comment

by:adamsfamily
ID: 7220920
Hi Hemanth,

the most important thing is, the database to work securely. I've decided to use Word documents. The possibilities to manipulate with a RichText field are really poor :-(

What now? Delete the question or should I accept your comment, what's you opinion?

~adams
0
 
LVL 24

Accepted Solution

by:
HemanthaKumar earned 100 total points
ID: 7221060
Well here are your options.

By deleting you are going to lose the script that I provided, which might come handy some time later.

By accepting the solution, you will keep the code for future and as well increase my score in my profile, which in turn will also give you points in future if someone is interested in this question.

So choice is yours and I am happy with my current ranking. I am sure there will be some requirement similar to yours and I have a solution ready made.

Cheers
~Hemanth

PS: I notice that you too use ~ symbol in your signature. gr8
0
 

Author Comment

by:adamsfamily
ID: 7235350
I accepted a bad comment as the answer for this question.

The solution is Hemanth's script above, of course.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 7239004
Unless the right person gets the credit, it is OK.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now