替换某个字符的代码
分类:电脑知识 发表于:2009-08-23 10:20:48 评论(0)
要替换某个字符的代码:
如将“<”替换成“& l t ;”
将“>”替换成“& g t ;”
若要替换双引号,则以两个双引号表示。
代码如下:
<%
Function outHTML(str)
Dim sTemp
sTemp = str
outHTML = ""
If IsNull(sTemp) = True Then
Exit Function
End If
sTemp = Replace(sTemp, "<", "& l t ;")
sTemp = Replace(sTemp, ">", "& g t ;")
sTemp = Replace(sTemp, """", "& q u o t ;")
outHTML = sTemp
End Function
str="要替换的字符串"
ss=outHTML(str)
response.write ss
%>