源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Highlight patterns within strings

  • 时间:2022-07-07 13:43 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Highlight patterns within strings
[u]复制代码[/u] 代码如下:
'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
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部