asp.net學習筆記 HTMLEncode HTMLDecode URLEncode

HTMLEncode 方法對指定的字符串應用 HTML 編碼。web

語法
Server.HTMLEncode( string )

參數
string 
指定要編碼的字符串。 
示例
腳本瀏覽器

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

輸出編碼

The paragraph tag: &lt;P&gt;

注意 以上輸出將被 Web 瀏覽器顯示爲code

The paragraph tag: <P>

若是查看一下源文件或以文本方式打開一個 Web 頁,您就能夠看到已編碼的 HTML字符串

get

HTMLDecodestring

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

輸出: The paragraph tag: <P>date


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

相關文章
相關標籤/搜索