首页 > 学院 > 开发设计 > 正文

UrlEncode 和 HtmlEncode

2019-11-17 02:33:13
字体:
来源:转载
供稿:网友

UrlEncode 和 HtmlEncode

UrlEncode

是将指定的字符串按URL编码规则,包括转义字符进行编码。

1 void Main()2 {3     string rawUrl = "http://www.demo.com?key=测试";4     string urlEncode = System.Web.HttpUtility.UrlEncode(rawUrl);5     urlEncode.Dump();6 }
View Code

HtmlEncode

是将html源文件中不容许出现的字符进行编码,通常是编码以下字符:"<"、">"、"&"、"""、"'"等。

1 void Main()2 {3     string rawTxt = "会被转义的字符:< > & /" '";4     string htmlEncode = System.Web.HttpUtility.HtmlEncode(rawTxt);5     htmlEncode.Dump();6 }
View Code


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表