Highlight patterns within strings
更新時(shí)間:2007年04月04日 00:00:00 作者:
復(fù)制代碼 代碼如下:
'Replaces pattern with highlighted replacement (using style) and preserves case
Public Function highlight(strText, strFind)
Dim objRegExp, i, strHighlight
'Split the search terms into an array
Dim arrFind
arrFind = Split(strFind, " ")
'Initialize the regular expression object to perfom the search
Dim oMatches, sMatch
Set oregExp = New RegExp
oregExp.Global = True 'Returns all matches to the search term
oregExp.IgnoreCase = True 'Case insensitive
'Loop through the array of search terms to find matches
For i = 0 to UBound(arrFind)
oregExp.Pattern = arrFind(i) 'Sets the search pattern string
Set oMatches = oregExp.Execute(strText) '// performs the search
for each match in oMatches
'Build the code to be used to highlight results
strHighlight = "<span class=""highlight"">" & match.value & "</span>"
next
'Replace matches from the search with the above code
strText = oregExp.Replace(strText, strHighlight)
Next
highlight = strText
Set objRegExp = Nothing
End Function
相關(guān)文章
ASP將數(shù)字轉(zhuǎn)中文數(shù)字(大寫金額)的函數(shù)
項(xiàng)目中遇到想將阿拉伯金額數(shù)字轉(zhuǎn)為中文漢字?jǐn)?shù)字形式,下面腳本之家小編就為大家分享一下ASP將數(shù)字轉(zhuǎn)中文數(shù)字的函數(shù)的實(shí)現(xiàn)方法,需要的朋友可以參考下2020-09-09好久沒(méi)發(fā)布新玩意,完成了tsys的少年不在版
好久沒(méi)發(fā)布新玩意,完成了tsys的少年不在版...2007-01-01ASP中解決“對(duì)象關(guān)閉時(shí),不允許操作?!钡脑幃悊?wèn)題……
本文解決ASP中“對(duì)象關(guān)閉時(shí),不允許操作?!钡脑幃悊?wèn)題,找到問(wèn)題的根本,才能真正意義上解決,供大家參考了。2016-03-03JavaScript在ASP頁(yè)面中實(shí)現(xiàn)掩碼文本框效果代碼
在網(wǎng)頁(yè)中輸日期、時(shí)間、IP地址等需要一定的格式限制,否則將會(huì)程序?qū)?huì)很難和程序溝通2012-08-08