<% if sid<>-1 then set sj=conn.execute("select art_type,id from art_type where id in(select sid from art_type where id="&id&")") end if %>

 您现在的位置: 首页 -> 技术文章 ->

 
:::启源思域 服务导航:::
实现搜索结果的关键词变色标注的程序
 

<% 
        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 
   
%>

上一篇: 用ASP实现简单的繁简转换

下一篇: ASP导出Excel数据的四种方法

      联 系 方 式
      在 线 帮 助
      汇 款 方 式
      站 内 地 图

本站关键词:网站建设 | 北京网站建设 | 网站制作 | 网站建设公司 | 网页设计 | 网站推广 | 网站维护 | 技术文章 | 域名主机 | 售后服务
Copyright © 2005-2008 北京启源思域网络技术有限公司 All Rights Reserved 欢迎来电详细咨询:010-69799974 24小时咨询热线:13810122025 京ICP备05033310号