手机
当前位置:查字典教程网 >编程开发 >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编程入门进阶(七):内置对象Server

如何使用FSO搜索硬盘文件

asp数个使用技巧

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

asp 中英文字符长度检测判断函数

关于静态页生成问题 突破form数量限制

文本搜索

以前写的一个分页存储过程,刚才不小心翻出来的

多附件上传组件演示

Jmail发邮件的例子

精品推荐
分类导航