How to replace a specific string in Rich text field with another string

HiI have form in whcih I have field called “comments” of type rich text.There are several documents created with this form. Now i have to replace a string in this comments field with another. As there are 100’s of documents manual work is difficult. So i tried an agent with @ReplaceSubString and @Replace but no luck. Not sure what I missed.

…Thanks in advance

Viswa.

Subject: How to replace a specific string in Rich text field with another string

Hi,

@ReplaceSubString should work fine for your need. The correct use for that formula is:

@ReplaceSubString(Comments; “Text to replace”; “New Text”)

I have used this formula in a situation almost the same as yours and worked fine.

Remembering that this function is Case sensitive.

Hope it helped a little

See ya

Subject: *Will only work with text field.

Subject: RE: *Will only work with text field.

Thank you very much to everybody for your responses. Looks like solution is not simple for RT items.

Subject: RE: How to replace a specific string in Rich text field with another string

The field type in my case is “Rich text”.Not sure whether these functions work with rich text or not. I tried extracting text from rich text and then try replace but still no luck.

Subject: RE: How to replace a specific string in Rich text field with another string

It shows any error message or just don’t apply the changes?

I was looking for some more information on the formula and I think you could try something like this:

FIELD Comments := @ReplaceSubString(Comments; “Text to be replaced”; “New Text”);

I’ve did a test with a body field on a e-mail document and it worked fine.

Subject: RE: How to replace a specific string in Rich text field with another string

I think the problem is with RT. Now I did see the error message in field value : “Text expected”. If I change the field as Text then its working. So not sure how i can i achieve with RT.

Subject: RE: How to replace a specific string in Rich text field with another string

Accessing and modifying rich text is a little more complex than that. Probably the easiest method to use for a one-time operation is to export the documents to a NotesStream using DXL, reading the stream text into a string, then using Replace against the string, writing the string to a NotesStream and re-importing the DXL (in LotusScript).

The LotusScript documentation you’ll need can be found in:

NotesNoteCollection

NotesDXLExporter

NotesStream

Replace

NotesDXLImporter

The examples in the NotesNoteCollection, NotesDXLExporter and NotesDXLImporter are clear and should make the process fairly easy.

Note: if the phrase to be replaced shows up in a bunch of places that it shouldn’t be replaced as well as in the rich text fields, you’ll proably want to export to a NotesDomParser and use standard DOM Level 3 methods in conjunction with Replace in order to ensure that you are only changing the elements you want to change.

Subject: RE: How to replace a specific string in Rich text field with another string

Actually there is a better solution for that… try FindAndReplace method in NotesRichTextRange. It works great with RT field.

Subject: RE: How to replace a specific string in Rich text field with another string

You know – you’re right. However, it has its limitations (like its inability to deal with hotspots and so on). There are enough problems with the native rich text methods that I almost never think to use any of them – DXL is at least as easy and much more versatile.

Subject: How to replace a specific string in Rich text field with another string

There is a FindAndReplace method in the NotesRichTextRange class. It isn’t perfect, but it does what you ask.