手机
当前位置:查字典教程网 >编程开发 >ASP教程 >Highlight patterns within strings
Highlight patterns within strings
摘要:复制代码代码如下:'Replacespatternwithhighlightedreplacement(usingstyle)andpres...

复制代码 代码如下:

'Replacespatternwithhighlightedreplacement(usingstyle)andpreservescase

PublicFunctionhighlight(strText,strFind)

DimobjRegExp,i,strHighlight

'Splitthesearchtermsintoanarray

DimarrFind

arrFind=Split(strFind,"")

'Initializetheregularexpressionobjecttoperfomthesearch

DimoMatches,sMatch

SetoregExp=NewRegExp

oregExp.Global=True'Returnsallmatchestothesearchterm

oregExp.IgnoreCase=True'Caseinsensitive

'Loopthroughthearrayofsearchtermstofindmatches

Fori=0toUBound(arrFind)

oregExp.Pattern=arrFind(i)'Setsthesearchpatternstring

SetoMatches=oregExp.Execute(strText)'//performsthesearch

foreachmatchinoMatches

'Buildthecodetobeusedtohighlightresults

strHighlight="<spanclass=""highlight"">"&match.value&"</span>"

next

'Replacematchesfromthesearchwiththeabovecode

strText=oregExp.Replace(strText,strHighlight)

Next

highlight=strText

SetobjRegExp=Nothing

EndFunction

【Highlight patterns within strings】相关文章:

asp分页的一个类

asp数个使用技巧

用XMLHTTP来偷东西哈!

Ajax+ASP和Flash+ASP数据读取取方法有些相似的实现方法

文本搜索

ASP常用函数:getIMG()

利用ActiveX控件InetCtls.Inet在ASP中实现新闻小偷

ASP编程入门进阶(七):内置对象Server

asp调用二级分类代码

javascript asp教程服务器对象

精品推荐
分类导航