南强小屋 Design By 杰米
在这种配置下我们要实现关键词不区分大小写搜索并高亮显示要借助ASP的正则处理了,请看下面代码:
复制代码 代码如下:
<%
Function Takeout(patrn,string1,colors)
'提取搜索关键字匹配文字
Dim regEx, Match, Matches, tt ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分大小写。
regEx.Global = True ' 设置全局可用性。
Set Matches = regEx.Execute(string1) ' 执行搜索。
For Each Match in Matches ' 遍历 Matches 集合。
RetStr = RetStr & Match.Value & " "
Next
RetStr = trim(RetStr)
if instr(RetStr," ")>0 then
for tt = 0 to ubound(split(RetStr," "))
string1 = replace(string1,split(RetStr," ")(tt),"<font color="""&colors&""">"&split(RetStr," ")(tt)&"</font>")
next
else
string1 = replace(string1,RetStr,"<font color="""&colors&""">"&RetStr&"</font>")
end if
Takeout = string1
End Function
response.write Takeout("jOeKOe", "Joekoe乔客双语版","red")
Function Highlight(strContent,keyword) '标记高亮关键字
Dim RegEx
Set RegEx=new RegExp
RegEx.IgnoreCase =True '不区分大小写
RegEx.Global=True
Dim ArrayKeyword,i
ArrayKeyword = Split(keyword," ")'用空格隔开的多关键字
For i=0 To Ubound(ArrayKeyword)
RegEx.Pattern="("&ArrayKeyword(i)&")"
strContent=RegEx.Replace(strContent,"<font color=red>$1</font>" )
Next
Set RegEx=Nothing
Highlight=strContent
End Function
response.write Highlight("Joekoe乔客双语版","jOeKOe")
%>
复制代码 代码如下:
<%
Function Takeout(patrn,string1,colors)
'提取搜索关键字匹配文字
Dim regEx, Match, Matches, tt ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分大小写。
regEx.Global = True ' 设置全局可用性。
Set Matches = regEx.Execute(string1) ' 执行搜索。
For Each Match in Matches ' 遍历 Matches 集合。
RetStr = RetStr & Match.Value & " "
Next
RetStr = trim(RetStr)
if instr(RetStr," ")>0 then
for tt = 0 to ubound(split(RetStr," "))
string1 = replace(string1,split(RetStr," ")(tt),"<font color="""&colors&""">"&split(RetStr," ")(tt)&"</font>")
next
else
string1 = replace(string1,RetStr,"<font color="""&colors&""">"&RetStr&"</font>")
end if
Takeout = string1
End Function
response.write Takeout("jOeKOe", "Joekoe乔客双语版","red")
Function Highlight(strContent,keyword) '标记高亮关键字
Dim RegEx
Set RegEx=new RegExp
RegEx.IgnoreCase =True '不区分大小写
RegEx.Global=True
Dim ArrayKeyword,i
ArrayKeyword = Split(keyword," ")'用空格隔开的多关键字
For i=0 To Ubound(ArrayKeyword)
RegEx.Pattern="("&ArrayKeyword(i)&")"
strContent=RegEx.Replace(strContent,"<font color=red>$1</font>" )
Next
Set RegEx=Nothing
Highlight=strContent
End Function
response.write Highlight("Joekoe乔客双语版","jOeKOe")
%>
标签:
asp,关键词,高亮显示
南强小屋 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
南强小屋 Design By 杰米
暂无asp 关键词高亮显示(不区分大小写)的评论...