Highlight patterns within strings_ASP教程-查字典教程网
Highlight patterns within strings
Highlight patterns within strings
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:'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

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新ASP教程学习
    热门ASP教程学习
    编程开发子分类