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

ASP
asp下检查表中是否存在某个字段(列)函数
ASP批量更新代码
asp飞飞无限级分类v1.0 Asp+sql+存储过程+ajax提供下载
比较详细的ASP rs.open语句详细说明
可以应用到马克斯电影站生成Rss Feed的代码
ASP 无限级分类实现
从数据库中读取记录横向排列
ASP动态级联菜单实现代码
网上用的比较多的asp级联菜单效果代码
ASP提高数据显示效率-缓存探幽
asp经常被忽视的一种死循环
关于Asp代码与页面的分离模板技术
用GetString提高ASP的速度
用cookies实现闪电登录论坛方法
一个不太让人讨厌的自动弹出窗口
asp格式化日期时间格式的代码
ASP变量加变量实现代码
asp向数据库插入数据的方法rs
asp上传带显示的代码
asp防止垃圾留言代码

ASP 中的 Highlight patterns within strings


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