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

2016-01-29 20:25 16 1 收藏

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

【 tulaoshi.com - ASP 】

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

来源:https://www.tulaoshi.com/n/20160129/1511141.html

延伸阅读
标签: 冬季养生 健康
冬季气候下降,加之寒风侵袭会带给皮肤一系列变化,皮肤的毛细血管为了防止皮肤散热而收缩,”皮肤的水分和Tulaoshi.Com皮脂也相应减少,皮肤的新陈代谢变得缓慢。因此,冬季应注意皮肤护理,尤其是干性皮肤更要注意。冬季护理皮肤最重要的是防止寒冷对皮肤的刺激和提高皮肤的御寒能力。 .hzh {display: none; } (l)使用弱酸性洗面...
标签: Web开发
这个可以用jquery的一个插件cluetip 地址下载是:plugins.learningjquery.com/cluetip/demo/ 下面简单讲解下用法: 1 首先当然要放JQUERY的基本JS,和这个插件的JS了,如: a class="title" href="#" title="This is the title|The first set of contents comes after the first delimiter..... $('a.title').cluetip({splitTitle: '|'}); ...
夏季老人避暑四关键词 想让家中的老人安然度夏,避免中暑就要懂得一些关键点,要知道做到这么一些关键的事项就可以让老人处在夏季中也不所中暑了。 1、夏季保健——运动 适度锻炼、间隔半小时再洗澡 中老年人夏季运动最好在清晨或傍晚较凉爽的时间进行,场地可选择公园、湖边或树下阴凉的地...
标签: 春季养生
到了春季我们常常关注 春季养生 ,那么春季养生是养生什么呢?下面给大家分享春季养生的几个关键词即:养阳、养阴、养脑、养脾、养肾、养肝。 生活小窍门 1、养阳 阳,是指人体阳气, 中医 认为阳气者,卫外而为,即指阳气对人体起着保卫作用,可使人体坚固,免受自然界六淫之气的侵袭。春天在饮食方面,要遵照《黄帝内经》里提...
下面来一起看看母乳喂养的关键词。 关键词:前奶、后奶 每次喂奶时,根据母乳分泌的先后,乳汁还有前奶和后奶之分。 先吸出来的奶叫“前奶”,虽然看上去比较稀薄,却富含水分、蛋白质,这也让纯母乳喂养的宝宝,在出生后4个月内一般不需要额外补充水。“前奶” 以后的乳汁,变成了白色,比较浓稠,这便是“后奶”了。...

经验教程

515

收藏

61
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部