asp 标记字符串中指定字符变色不区分大小写
发布时间:2016-12-29 来源:查字典编辑
摘要:普通的替换函数复制代码代码如下:publicfunctionHighLight(S,F)dimtL,tM,tR,ktL=""tM=""tR=...
普通的替换函数
复制代码 代码如下:
public function HighLight(S,F)
dim tL,tM,tR,k
tL=""
tM=""
tR=S
k=instr(1,tR,F,1)
do while k>0
tL=tL & left(tR,k-1)
tM=mid(tR,k,len(F))
tL=tL & "<span>" & tM & "</span>"
tR=right(tR,Len(tR)-len(F)-k+1)
k=instr(1,tR,F,1)
loop
HighLight=tL & tR
end function
tS="abcaBcabCaBCabcaBCa"
tF="bc"
response.Write(tS)
response.Write("<br/>")
response.Write(HighLight(tS,tF))
正则表达式
复制代码 代码如下:
Function HighLight(S,F)
Dim regEx
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "(" & F & ")"
HighLight = regEx.Replace(S,"<span>$1</span>")
End Function
Response.write HighLight("abcaBcabCaBCabcaBCa","bc")