Add Blank line with Find/Replace

Hi,

I’m trying to Find/Replace a specific string in a (computed) richtext field with a new string which includes a blank line.

Finding the string and replacing it is no problem, but the blank lines in the replacement string are omitted, which causes an issue with the layout.

Any help would be very much appreciated.

Here’s the code I use:

Dim updatestring as string

updatestring = “</Latest Entry>” + Chr(13) + “This is a test”

Dim rtitem As notesrichtextitem

Dim rtnav As NotesRichTextNavigator

Dim rtrange As NotesRichTextRange

Set rtitem = doc.GetFirstItem(“DPHistory”)

Set rtnav = rtitem.CreateNavigator

Set rtrange = rtitem.CreateRange

Call rtrange.FindandReplace(“</Latest Entry>”,updatestring)

Subject: Add Blank line with Find/Replace

Try using Chr(13) + Chr(13).

Subject: RE: Add Blank line with Find/Replace

Thanks for the suggestion, but still no luck, they’re all omittedAny other ideas?

Subject: RE: Add Blank line with Find/Replace

Try Chr(10) + Chr(10). It’s a little different than Chr(13).

Subject: RE: Add Blank line with Find/Replace

Still no luck. Chr(13), Chr(10),… it makes no difference. All blank lines are omitted.

Anybody have another suggestion?

Subject: RE: Add Blank line with Find/Replace

You can try Chr(0), which is the newline indicator in rich text, but it may well not work. There used to be a bug since the Notes cure is implemented in C/C++ and Chr(0) is also a null character, which is a string terminator in C/C++. Still, give it a try. I know the basic logic is correct, as I tried it with our Midas Rich Text LSX

Set rtitem = New GeniiRTItem

Call rtitem.ConnectBackend(doc.Handle, “Body”, True)

Call rtitem.Everything.ReplaceText(“</Latest Entry>”, “</Latest Entry>”+Chr(0)+“This is a test”)

Call rtitem.Save

and it worked as expected. So, if that bug has been fixed, the same logic should apply

Dim updatestring as string

updatestring = “</Latest Entry>” + Chr(0) + “This is a test”

Dim rtitem As notesrichtextitem

Dim rtnav As NotesRichTextNavigator

Dim rtrange As NotesRichTextRange

Set rtitem = doc.GetFirstItem(“DPHistory”)

Set rtnav = rtitem.CreateNavigator

Set rtrange = rtitem.CreateRange

Call rtrange.FindandReplace(“</Latest Entry>”,updatestring)

but I didn’t actually try it this way on anything later than 6.5.3, where the bug is still exhibited. Maybe I’ll give it a try in Notes 8 beta.

Subject: RE: Add Blank line with Find/Replace

On 7.0.2 this doesn’t work. For some reason when using Chr(0) the replace doesn’t happen at all.

Any other suggestions anyone?

Thanks

B

Subject: RE: Add Blank line with Find/Replace

This is a symptom of the bug I mentioned. Try changing your code to use

updatestring = “</Latest Entry> new text here” + Chr(0) + “This is a test”

and you will see that the new text here is added, but not the rest. That is because the Chr(0) was treated as the end of the string.

Subject: RE: Add Blank line with Find/Replace

This thing is driving me mad. Even the bit before the Chr(0) isn’t there. When using Chr(0) nothing happens, while with Chr(10) or Chr(13) the text is replaced but without the blank lines…

Thank you all for your suggestions. Any other things I can try are greatly appreciated.