当前位置:首页 > Windows程序 > 正文

解决办法: 右击项目==》添加引用==》.NET==》System.Web==》确定 System.Web.HttpU

2024-03-31 Windows程序

在Asp.net中可以使用Server.HTMLEncode和Server.URLEncode 将文本或URL的特殊字符编码,
但在控制台或Winform措施中没有步伐使用到这些要领,


解决步伐:
右击项目==》添加引用==》.NET==》System.Web==》确定
System.Web.HttpUtility.HtmlEncode(str);
System.Web.HttpUtility.HtmlDecode(str);
System.Web.HttpUtility.UrlEncode(str);
System.Web.HttpUtility.UrlDecode(str);
编码后得到的字串和用Server.URLEncode编码得到的不一样,那边接收到的也是乱码??
编码时可以指定编码的,,如
System.Web.HttpUtility.UrlEncode(str,System.Text.Encoding.Unicode);
System.Web.HttpUtility.UrlEncode(str,System.Text.Encoding.UTF8);
System.Web.HttpUtility.UrlEncode(str,System.Text.Encoding.GetEncoding( "GB2312 "));

解码也可以指定编码的
System.Web.HttpUtility.UrlDecode(str,System.Text.Encoding.Unicode);
System.Web.HttpUtility.UrlDecode(str,System.Text.Encoding.UTF8);
System.Web.HttpUtility.UrlDecode(str,System.Text.Encoding.GetEncoding( "GB2312 "));


MessageBox.Show(System.Web.HttpUtility.UrlEncode(s,System.Text.Encoding.GetEncoding("GB2312")).ToUpper());

标签:

原文地点:https://www.cnblogs.com/rainbowaab/p/8807399.html

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/33693.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494587访问次数
  • 建站天数
  • 友情链接