壹次网首页 | 工具源码首页 | 技术文章首页 | 文章分类 | | |

文章搜索: 分类 关键字
您的位置:首页网络编程ASP/shtml → replace不区分大小写(高亮显示关键字)的两个函数
replace不区分大小写(高亮显示关键字)的两个函数
添加日期:2008-5-17 7:32:23     [ ]
<% 
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") 
%>
出处:论坛转载 作者:佚名 点击:
 热点文章
·photoshop制作香烟、烟头、烟雾
·photoshop图片卷角、翻页效果的制作
·用U盘或移动硬盘装《深山红叶袖珍系统Win PE启动..
·photoshop经典恐怖片海报效果教程
·ghost.pif最新变种手动查杀,ARP欺骗挂马+KAV让..
·photoshop制作3D立体小人和字体
·photoshop水晶球质感表现 - 关于光影的细节
·关于zend解密的程序
·王晨昀:谁来拯救中小网站?
·photoshop泛黄、陈旧纸张效果的制作
 推荐文章
·如何彻底删除一个不需要的系统服务
·模仿QQ和MSN消息提示的效果
·CC攻击的思路及防范方法
·广告联盟的一些评价
Powered by yici.net
CopyRight (C) 2006-2012 版权所有   [ 依次网 ];未经授权,任何人不得抄袭、仿冒本站
ICP备案:苏ICP备05011771号 证书下载 ICP证号:苏ICP证040301
仪征广目网络信息服务有限公司 版权所有