手机
当前位置:查字典教程网 >编程开发 >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】相关文章:

构建免受 FSO 威胁虚拟主机(三)

用正则和xmlHttp实现的asp小偷程序

如何使用FSO搜索硬盘文件

如何采集静态文章系统

asp数个使用技巧

asp分页的一个类

Jmail发邮件的例子

javascript asp教程服务器对象

多附件上传组件演示

Asp获取url地址的实例

精品推荐
分类导航