当前位置:首页>>开发编程>>ASP>>新闻内容
实现搜索结果的关键词变色标注的程序
作者:飞鸟 发布时间:2003-10-8 2:48:08 文章来源:
<%
' 以前写全文检索程序的时候写的.
' 原创 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
  
%>

最新更新
·数据库被挂马的ASP处理方法
·ASP快速获取远程文件大小的方
·用ASP屏蔽迅雷和旋风下载工具
·解决ASP中传送中文参数乱码的
·ASP+AJAX做类似Google的搜索
·ASP的一个非常棒的Debug类(
·ASP中常用的服务器检测源代码
·优化ASP中执行SQL效率的五个
·ASP种msxml3.dll 800c0005错
·挂QQ的ASP版本网页源代码
相关信息
·ASP智能搜索的实现
画心
愚爱
偏爱
火苗
白狐
画沙
犯错
歌曲
传奇
稻香
小酒窝
狮子座
小情歌
全是爱
棉花糖
海豚音
我相信
甩葱歌
这叫爱
shero
走天涯
琉璃月
Nobody
我爱他
套马杆
爱是你我
最后一次
少女时代
灰色头像
断桥残雪
美了美了
狼的诱惑
我很快乐
星月神话
心痛2009
爱丫爱丫
半城烟沙
旗开得胜
郎的诱惑
爱情买卖
2010等你来
我叫小沈阳
i miss you
姑娘我爱你
我们都一样
其实很寂寞
我爱雨夜花
变心的玫瑰
犀利哥之歌
你是我的眼
你是我的OK绷
贝多芬的悲伤
哥只是个传说
丢了幸福的猪
找个人来爱我
要嫁就嫁灰太狼
如果这就是爱情
我们没有在一起
寂寞在唱什么歌
斯琴高丽的伤心
别在我离开之前离开
不是因为寂寞才想你
爱上你等于爱上了错
在心里从此永远有个你
一个人的寂寞两个人的错