28,409
社区成员




tr="1232测试测俄方我测试测俄方gg测试测俄方你测试测俄方43645测试测俄方他测试测俄方ddgfd "
response.Write WordReplace(str,"我|你|他")
function lmid(str)
if len(str)>5 then
lmid="..."&right(str,5)
else
lmid=str
end if
End Function
function WordReplace(strContent,word)
Set objRegExp=New RegExp
Set Reg=New RegExp
objRegExp.IgnoreCase=true
objRegExp.Global=true
objRegExp.Pattern="([^" & word & "]+)(" & word & ")"
Reg.IgnoreCase=false
Reg.Global=false
set Matches=objRegExp.Execute(strContent)
set objRegExp=nothing
if Matches.Count<>0 then
For Each Match in Matches
Reg.Pattern=""&Match.SubMatches(0)&"(" & word & ")"
str=Reg.replace(strContent,""&lmid(Match.SubMatches(0))&"<span style=""color:#ff0000"">$1</span>")
next
end if
WordReplace=str
set Reg=nothing
End Function
'搜索结果标题
xw_coname=replace(Rs("title"),word,"<font color=red>"&word&"</font>")
'搜索结果截取简介
xw_cont=trim(Rs("content"))
'搜索结果处理
if instr(xw_cont,word) then
a=len(xw_cont)
b=instr(xw_cont,word)
if b<50 then c=left(xw_cont,b+1) else c="..."&mid(xw_cont,b-50,55)
if a-(b+len(word))<50 then d=right(xw_cont,a-(b+len(word))+1) else d=mid(xw_cont,b,50)&"..."
xw_coms=c&d
else
xw_coms=Trim(left(xw_cont,100))&"..."
end if
xw_coms=replace(xw_coms,word,"<font color=red>"&word&"</font>")
result= replace(result,search,"<font color=red>"&search&"</font>")
<%
'用正则表达式突出显示字符串中查询到的单词的函数
Function BoldWord(strContent,word)
if IsNull(strContent) then exit function
dim objRegExp
Set objRegExp=new RegExp
objRegExp.IgnoreCase =true
objRegExp.Global=True
objRegExp.Pattern="(" & word & ")"
strContent=objRegExp.Replace(strContent,"<span style=""color:#ff0000"">$1</span>" )
Set objRegExp=Nothing
BoldWord=strContent
End Function
%>