hi, I have written a highlight function based on an array of words. Apparently was working fine until I added entities. Could someone suggest an alternative way to this problem?
>>highlight(list_of_words, text)
Function Highlight(ByVal searchStr As String, _
ByVal inputTxt As String) As String
Dim regexp As Regex
Dim intSearchLoopCounter As Integer
Dim arrySearchWord As String() 'Array to hold the words to be searched for
'Split each word to be searched up and place in an array
arrySearchWord = Split(Trim(searchStr), " ")
regexp = New Regex("", RegexOptions.IgnoreCase)
'Loop round to search for each word to be searched
For intSearchLoopCounter = 0 To UBound(arrySearchWord)
InputTxt = Regex.Replace(InputTxt, "\b(" & Regex.Escape(arrySearchWord(intSearchLoopCounter)) & ")\b", _
New MatchEvaluator(AddressOf ReplaceKeyWords), RegexOptions.IgnoreCase)
Next
Return InputTxt
End Function
Public Function ReplaceKeyWords(ByVal m As Match) As String
Return "<span class=highlight>" & m.Value & "</span>"
End Function
Sample Text: this is a sample "test" and I just want to highlight the words inside the array and nothing else
list_of_words: inside, array
thanks a lot
>>highlight(list_of_words, text)
Function Highlight(ByVal searchStr As String, _
ByVal inputTxt As String) As String
Dim regexp As Regex
Dim intSearchLoopCounter As Integer
Dim arrySearchWord As String() 'Array to hold the words to be searched for
'Split each word to be searched up and place in an array
arrySearchWord = Split(Trim(searchStr), " ")
regexp = New Regex("", RegexOptions.IgnoreCase)
'Loop round to search for each word to be searched
For intSearchLoopCounter = 0 To UBound(arrySearchWord)
InputTxt = Regex.Replace(InputTxt, "\b(" & Regex.Escape(arrySearchWord(intSearchLoopCounter)) & ")\b", _
New MatchEvaluator(AddressOf ReplaceKeyWords), RegexOptions.IgnoreCase)
Next
Return InputTxt
End Function
Public Function ReplaceKeyWords(ByVal m As Match) As String
Return "<span class=highlight>" & m.Value & "</span>"
End Function
Sample Text: this is a sample "test" and I just want to highlight the words inside the array and nothing else
list_of_words: inside, array
thanks a lot