asp 标记字符串中指定字符变色不区分大小写
程序员文章站
2022-08-10 17:51:04
普通的替换函数
复制代码 代码如下:public function highlight(s,f) dim tl,tm,tr,k tl="" tm="" tr=s k=in...
普通的替换函数
复制代码 代码如下:
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 style='color:red'>" & 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 style='color:red'>$1</span>")
end function
response.write highlight("abcabcabcabcabcabca","bc")
上一篇: asp正则替换链接实现伪静态效果
下一篇: PHP响应post请求上传文件的方法