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

ASP
编写通用的asp防注入程序
vbs(asp)下的Function 语句
ASP中类Class相关内容的整理资料
字符批量替换程序asp服务器版
旁注-网站小助手旭方修改免杀asp版
用正则表达式写的HTML分离函数
asp中"无限流"分页程序代码
asp的一个日期格式化函数
asp中创建多级目录的两段代码
asp中去除内容HTML标签的三个function函数
chr(9)、chr(10)、chr(13)、chr(32)、chr(34)讲解
方便的大家admin及admin888 经过 md5加密后16位和32位代码
可用的ASP无重复数字随机函数, 数组实现, 并应用于随机显示记录集
asp动态级联菜单代码
ASP中经常使用的SQL语句与教程说明
实例分析之用ASP编程实现网络内容快速查找的代码
服务端 VBScript 与 JScript 几个相同特性的写法与示例
ASP 环境下 VBS 事件应用 示例代码
asp 之上传漏洞终结篇
asp中一段防SQL注入的通用脚本

ASP 中的 Highlight patterns within strings


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 42 ::
收藏到网摘: 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