中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > Web开发 > Asp > 综合文章
实现搜索结果的关键词变色标注的程序
作者:佚名 时间:2006-11-05 16:39 出处:互连网 责编:月夜寒箫
              摘要:实现搜索结果的关键词变色标注的程序
<%
' 以前写全文检索程序的时候写的.
' 原创 by 飞鸟@dev-club.com
' Email: flybird@dev-club.com
' ie5.5 脚本引擎 required

   dim patern
   dim found
  
   dim str
   dim result
  
   patern="(a)|(b)"
   str=" A dog fall in love with a cat. Can you believe?"
   result=""  
   call getMatchText(str,result,false)
   Response.Write result

   sub getMatchText(byref str,byref result,isNeedTrunc)
     'on error resume next
     Dim regEx, Match, Matches
     dim tStr
     Set regEx = New RegExp     ' 建立正则表达式。    
     regEx.Pattern = (patern)  ' 设置模式。
     regEx.IgnoreCase = True     ' 设置是否区分字符大小写。
     regEx.Global = True     ' 设置全局可用性。
     Set Matches = regEx.Execute(str)  ' 执行搜索。  
     if err.number<>0 then
       response.write "错误1:" & err.description
       err.clear
       exit sub
     end if
     if matches.count <>0 then
       dim startIndex      
       dim myMatchValue
       startIndex=1
       for each match in matches
         if (instr(str,match.value)>0) then
           if instr(str,match.value)-50 >0 then
             startIndex=instr(str,match.value)-50
           else
             startIndex=1
           end if
           myMatchValue=match.value
           exit for
         end if
       next
       if isNeedTrunc then
         result= (mid(str,startIndex,strLength(myMatchValue)+100))
       else
         result= (str)  
       end if
       for each match in matches
         if not(instr(result,"<font color=red>" & match.value & "</font>")>0) then
           result=replace(result,match.value,"<font color=red>" & match.value & "</font>" )
         end if
       next
       found=true
     else
       found=false
     end if  
     set regEx=nothing
   end sub
  
%>
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有