软件教程

replace不区分大小写的两个函数

来源: 本站    类别: 软件教程    日期: 2013/11/1

 以下是函数源代码:
<%
Function Takeout(patrn,string1,colors)
’提取搜索关键字匹配文字
  Dim regEx, Match, Matches, tt        ’ 建立变量。
  Set regEx = New RegExp         ’ 建立正则表达式。
  regEx.Pattern = patrn         ’ 设置模式。
  regEx.IgnoreCase = True         ’ 设置是否区分大小写。
  regEx.Global = True            ’ 设置全局可用性。
  Set Matches = regEx.Execute(string1)      ’ 执行搜索。
  For Each Match in Matches         ’ 遍历 Matches 集合。
    RetStr = RetStr & Match.Value & " "
  Next
  
  RetStr = trim(RetStr)
  if instr(RetStr," ")>0 then
   for tt = 0 to ubound(split(RetStr," "))
  string1 = replace(string1,split(RetStr," ")(tt),"<font color="""&colors&""">"&split(RetStr," ")(tt)&"</font>")
 next
  else
  string1 = replace(string1,RetStr,"<font color="""&colors&""">"&RetStr&"</font>")
  end if
  Takeout = string1
End Function
response.write Takeout("jOeKOe", "Joekoe乔客双语版","red")
Function Highlight(strContent,keyword) ’标记高亮关键字
    Dim RegEx 
    Set RegEx=new RegExp 
    RegEx.IgnoreCase =True ’不区分大小写
    RegEx.Global=True 
    Dim ArrayKeyword,i
    ArrayKeyword = Split(keyword," ")’用空格隔开的多关键字
    For i=0 To Ubound(ArrayKeyword)
        RegEx.Pattern="("&ArrayKeyword(i)&")"
        strContent=RegEx.Replace(strContent,"<font color=red>$1</font>" ) 
    Next
    Set RegEx=Nothing 
    Highlight=strContent 
End Function
response.write Highlight("Joekoe乔客双语版","jOeKOe")
%>

相关文章


Copyright © 2004 - 2024 CNHWW Inc. All Rights Reserved
石家庄市征红网络科技有限公司版权所有 邮政编码:050051
服务电话:0311-85315152 13931185013 在线客服QQ:81447932 / 81447933 邮箱: cnhww@163.com