asp.net学习笔记 HTMLEncode HTMLDecode URLEncode

HTMLEncode 方法对指定的字符串应用 HTML 编码。

语法
Server.HTMLEncode( string )

参数
string 
指定要编码的字符串。 
示例
脚本

<%= Server.HTMLEncode("The paragraph tag: <P>") %> 

输出

The paragraph tag: &lt;P&gt;

注意 以上输出将被 Web 浏览器显示为

The paragraph tag: <P>

如果查看一下源文件或以文本方式打开一个 Web 页,您就可以看到已编码的 HTML

HTMLDecode

<%= Server.HTMLDecode("The paragraph tag: &lt;P&gt") %>

输出: The paragraph tag: <P>


URLEncode
URLEncode 方法将 URL 编码规则,包括转义字符,应用到指定的字符串。

语法
Server.URLEncode( string )

参数 
String 
指定要编码的字符串。 
示例
脚本

<%Response.Write(Server.URLEncode(http://www.updateweb.cn)) %>

输出

http%3A%2F%2Fwww%2Eupdateweb%2Ecom


原文http://hi.baidu.com/zwfec/item/80e3ba18bbfa920ce75c36af

你可能感兴趣的:(asp.net学习笔记 HTMLEncode HTMLDecode URLEncode)