asp 替换

来源:百度知道 编辑:UC知道 时间:2024/09/24 20:26:45
文章里的 关键字
如:
关键字是:交谈,消息,电话
内容:交谈中请勿轻信汇款、中奖消息,勿轻易拨打陌生电话。交谈中请勿轻信汇款、中奖消息,勿轻易拨打陌生电话。
我想替换掉 关键字 但是只替换第一次出现的。

<%
Label="交谈,消息,电话"
Label=Split(Label,",")
for i=0 to UBound(Label)
Response.Write ""
next
%>

用正则:
<%
Function Replacestr(str,str0)'正则
Dim regEx
Set regEx = New RegExp
regEx.Pattern = str0
regEx.IgnoreCase = false
regEx.Global = false
Replacestr = regEx.Replace(str,"**")
End Function

a="交谈中请勿轻信汇款、中奖消息,勿轻易拨打陌生电话。交谈中请勿轻信汇款、中奖消息,勿轻易拨打陌生电话。"
b="交谈,消息,电话"'过滤的关键词,可以扩展,逗号要用英文标点
c=Split(b,",")
For i=0 To ubound(c)
a=replacestr(a,c(i))
next
response.write a
%>

用indexof()找到关键字第一次出现的位置,然后替换,就行了

有点深啊