当前位置: 首页 > 图文教程 > 网络编程 > ASP > 实现搜索结果的关键词变色标注的程序

ASP
超级ASP版DataGrid:SkyGrid本地下载
用QuickWAP组件结合ASP建设Wap站点
ASP中取得图片宽度和高度的类(无组件)
在ASP处理程序时显示进度
结合FSO操作和Aspjpeg组件写的Class
asp实现的7xi音乐网的采集源代码
用asp+xmlhttp编写web采集程序
推荐ASP超速入门视频教程
关于“未指定的错误”的问题 的比较正解的解决方法
用asp脚本实现限制IP访问
aspupload 3.0 下载与使用集锦
[教程+分享]具有良好体验度的Web注册系统
asp 实现视频显示的效果函数
asp实现图片右键滑轮控制大小的函数
彻底掌握ASP分页技术杂谈
aspupload文件重命名及上传进度条的解决方法附代码
ASPJPEG综合操作的CLASS类
asp通用采集函数冗余版可以保存文件到本地
使用ODBC数据库管理Serv-U的FTP用户及相关ASP编程[附源码示例下载]
[asp]阿里西西的alexa采集效果代码

ASP 中的 实现搜索结果的关键词变色标注的程序


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 33 ::
收藏到网摘: n/a

<%
' 以前写全文检索程序的时候写的.
' 原创 by 飞鸟@dev-club.com
' Email: [email protected]
' 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
  
%>