HttpServerUtility Server.HtmlEncode与Server.HtmlDecode
2010-09-21 08:28
405 查看
[title2][/title2]
一.HTMLEncode 方法对指定的字符串应用 HTML 编码。
语法
Server.HTMLEncode( string )
参数
string 指定要编码的字符串。示例
脚本<%= Server.HTMLEncode("The paragraph tag: <P>") %>
输出
The paragraph tag: <P>
注意 以上输出将被 Web 浏览器显示为
The paragraph tag: <P>
如果查看一下源文件或以文本方式打开一个 Web 页,您就可以看到已编码的 HTML
例子:对通过 HTTP 传输的字符串进行编码。该示例对名为 TestString 且包含文本“This is a <Test String>.”的字符串进行编码,然后将其复制到名为 EncodedString 的字符串中,新字符串的内容为“This is a <Test String>.”。
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
Server.HtmlEncode方法定义:对字符串进行 HTML 编码 。
意思就是 把字符 编码 为转义符。
例如:空格的的转义符是 小于号<的转义符是< 与符号 & 的转义符是:& 。
浏览器在解释转义符时,只将转义符对应的字符或者字符串显示在浏览器上,而不进行HTML的标记解释。
二、TMLDecode 方法对指定的字符串应用 HTML 反编码。
语法
Server.HTMLDecode( string )
参数
string 指定要反编码的字符串。相关文章推荐
- Server.HtmlEncode vs HttpUtility.HtmlEncode
- Server对象 HttpUtility.UrlDecode |UrlEncode |HtmlEncode
- 在用HttpUtility.HtmlDecode转义成html画面显示的时候遇到的奇怪问题
- Server.UrlEncode与HttpUtility.UrlDecode使用
- HttpUtility.UrlDecode(),HttpUtility()escape()、encodeURI()、encodeURIComponent()区别详解以及相应的前台解码和.net后台解码
- Server.UrlEncode与HttpUtility.UrlDecode使用
- HttpUtility.HtmlEncode
- javascript; JS版HtmlEncode方法,结果与C#中HttpUtility.HtmlEncode方法一样。
- Server.Htmlencode和Server.HtmlDecode的用法
- HttpUtility.HtmlEncode 方法 (String)
- Server.UrlEncode、HttpUtility.UrlDecode不同编码
- 关于HttpUtility.UrlEncode,HttpUtility.UrlDecode,Server.UrlEncode,Server.UrlDecode
- POST数据提交,关于System.Web.HttpUtility.HtmlEncode与System.Web.HttpUtility.UrlEncode的区别
- [转]Server.Htmlencode和Server.HtmlDecode的用法
- HttpUtility.Encode与Server.Encode
- 关于 HttpUtility.UrlEncode 和 HttpUtility.HtmlEncode 的区别
- Server.Htmlencode和Server.HtmlDecode的用法
- HttpUtility.UrlEncode 在 Encode 的时候, 将空格转换成加号('+'), 在 Decode 的时候将加号转为空格, 但是浏览器是不能理解加号为空格的, 所以如果文件名包含了空格, 在浏览器下载得到的文件, 空格就变成了加号
- HttpUtility.UrlDecode Server.UrlDecode 区别
- HttpUtility.UrlDecode Server.UrlDecode 区别