doHighlight

Search for occurrences of a keyword in a string and highlight them, by either bold, italic or boli-italic
With some work, we can add bootstrap highlighting, or some other html colors

Function doHighlight(my_sentence, word_to_highlight, my_fn)
 ' doHighlight Function
 ' Author: Anthony Biondo (anthony.biondo@kmhp.com)
 ' Description: Search for occurances of a keyword in a string and highlight them, by either bold, italic or boli-italic
 ' Inputs: String you want searched, word to highlight, and the type of highlight to perform.
 ' Types of highlight functions: b=bold; i=italic; bi=bold-italic
 ' Output: Returns the string with highlighting.
 Select Case lcase(my_fn)
 Case "b"
 my_output = "<B>" & word_to_highlight & "</B>"
 doHighlight = replace(my_sentence, word_to_highlight, my_output)
 Case "i"
 my_output = "<I>" & word_to_highlight & "</I>"
 doHighlight = replace(my_sentence, word_to_highlight, my_output)
 Case "bi"
 my_output = "<I><B>" & word_to_highlight & "</B></I>"
  doHighlight = replace(my_sentence, word_to_highlight, my_output)
 End Select
End function

Parameters

my_sentence, word_to_highlight, my_fn

Examples

response.write doHighlight(&#34;This is a test To find the word you, it will highlight your...&#34;, &#34;you&#34;, &#34;bi&#34;)

Views 170 Downloads 67

Perm link