设为首页
加入收藏
繁體中文
首 页客家风情客家影音山歌在线客家商城聊天室留言墙测字算命下载中心IT 技术客家论坛
您当前的位置:天南地北客家人 -> IT 技术-> ASP -> 正文 退出登录 用户管理
栏目导航
· ASP · JSP
· 网络安全 · NET专区
· XML专区 · PHP专区
热门文章
· ASP+JavaScript的完整的..
· [图文] 防范非法用户的侵..
· ASP从数据库中获取文件..
· 网络管理中的常用命令
· [图文] FSO组件操作实例..
· [图文] 千年虫二世诞生业..
· 网络常见木马的手工清除..
· [图文] 简单购物车教程
· 一个ASP(VBScript)简..
· 利用ASP远程获取内容
· 网络常见木马的手工清除..
· asp常用数据库连接方法..
相关文章
· ASP.NET中树形图的实现
· 用ASP实现对ORACLE数据库..
· asp实现k线图(在线)
· 嵌入式Web视频点播系统实..
· asp在SQL SER2k中新建帐..
· 一个不需要第三方组件,..
· Filter与updatebatch混合..
· asp中利用数组实现数据库..
· 在asp中通过getrows实现..
· 实现WEB中的@虚拟域名系..
· php实现ping
· 利用static实现表格的颜..
· 如何实现日期比较,暨实..
· 利用sql的存储过程实现d..
· 使用asp实现支持附件的邮..
实现搜索结果的关键词变色标注的程序
作者:佚名  来源:动网  发布时间:2008-4-16 11:34:43  发布人:Admin

减小字体 增大字体

<%
' 以前写全文检索程序的时候写的.
' 原创 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
  
%>

[] [返回上一页] [打 印] [收 藏]
上一篇文章:LCID地区代码
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论…]
关于本站 - 网站合作 - 免责声明 - 友情连接 - 网站地图 - 客家论坛
本站部份内容来自网络 如无意中侵犯了您的权利 请及时与我们联系 我们会尽快处理
Copyright © 2006-2012   天南地北客家人
Email:hakka360@sina.com   客家人QQ群:33754730
粤ICP备07019796号