Hi,I have a web application that highlights all the words found in a search query. I’m using the FindAndReplace function to add some HTML around each word to highlight it. My problem is, if I use the RT_REPL_ALL option on the FindAndReplace function, everything runs fine, but, if I don’t add this option, I lost all the italic parts of the paragraph where the word is located. Because I must use a loop I can’t use the RT_REPL_ALL option. Is this a known bug?
Here is my code:
…
'Get the number of replacements to do
nWord = 0
If rtnav.FindFirstString (tagStr, 7) Then
nWord = 1
While rtnav.FindNextString (tagStr, 7)
nWord = nWord + 1
Wend
End If
'If we can't find the special tag, we don't belong here
If nWord = 0 Then Exit Sub
Set rtrange = body.createRange
wordCount = 1
For wordCount = 1 To nWord
'Check in the current word is the first or the last word
If (wordCount = 1 Or nWord = 1) Then
firstWord = True
Else
firstWord = False
End If
If (wordCount = nWord Or nWord = 1) Then
lastWord = True
Else
lastWord = False
End If
'Build the forward and the reverse arrows
If (firstWord) Then
beforeCode = "["
Else
beforeCode = "[" + "<a style='" + tagStyle + "' href='#" + tag + Cstr(wordCount - 1) + "'><< </a>"
End If
If (lastWord) Then
afterCode = "]"
Else
afterCode = "<a style='" + tagStyle + "' href='#" + tag + Cstr(wordCount + 1) + "'> >></a>]"
End If
'Build the replace string
replaceStr = beforeCode + "<a tag='searchnav-" + tag + Cstr(wordCount) + "-' name='" + tag + Cstr(wordCount) + "'><font style='" + R_HIGHLIGHTPREFIX + "'>" + searchString + "</font></a>" + afterCode
'Replace the value
Call rtrange.FindandReplace (tagStr, replaceStr, 15)
body.Update
Next
…
If I replace the option number from 15 to 31, I can see the italic parts of the paragraph. But, obviously, I can’t get my links to work. Is this a bug or a misuse of the function?
Thanks!
Carl