帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
实现搜索结果的关键词变色标注的程序
作者:飞鸟 发布时间:2005-03-12 来源:开发者俱乐部
<%
' 以前写全文检索程序的时候写的.
' 原创 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实现对ORACLE数据库的操作  (2005-03-12)
 ·.net中即时消息发送的实现……  (2005-03-12)
 ·在Whidbey中实现Provider  (2005-03-12)
 ·J2ME 有助于在移动设备上实现支付  (2005-03-12)
 ·用J2ME在移动设备上实现动画  (2005-03-12)
 ·使用J2ME实现移动支付  (2005-03-12)
 ·如何使用XML实现多渠道接入网站的  (2005-03-12)
 ·用JDOM包实现生成XML文件的简单示  (2005-03-12)
 ·Zeus实现XML-JAVA的数据绑定  (2005-03-12)
 ·应用JDOM处理数据库到XML转换JSP  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统