当前位置: 首页 > 图文教程 > 网络编程 > ASP > Highlight patterns within strings

ASP
收集整理的ASP的常用内置函数
高手推荐的比较有用的ASP函数集合
ASP中JavaScript处理复杂表单的生成与验证
asp下tag的实现,简单介绍与部分代码
在ASP中用组件检测当前网卡地址的代码
asp中COM组件中如何连接数据库的代码
用ASP创建MDaemon用户的代码
ASP使用FSO读取模板的代码
ASP开发中可能遇到的错误信息中文说明大全(整理收集)
添加超级用户的.asp代码[蓝屏的原创,凯文改进,Ms未公布的漏洞]
全面优化ASP应用程序的性能的方法
实现ASP程序执行时间统计类的代码
ASP中利用execute实现动态包含文件的方法
asp中向文本框输出数据原样式的函数
ADODB.Stream组件Charset属性值集合
关于ASP代码的加密的几个方法
支持权重的无组件ASP广告显示代码
ASP下实现自动采集程序及入库的代码
asp读取远程文件并保存到本地代码
为什么ASP中执行动态SQL总报错误信息?提示语句语法错误

ASP 中的 Highlight patterns within strings


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 40 ::
收藏到网摘: n/a

复制代码 代码如下:

'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