不知道大家有没有注意过 字符串保存到数据库里是
这样的一段字符
要引用.net 自带的DLL Microsoft.JScript
这字符是 Escape编码
?
1 2 3 4 5 6 7 8 9 10 |
//Escape编码,同js
public static string Escape( string str)
{
return Microsoft.JScript.GlobalObject.escape(str);
}
//UnEscape解码,同js
public static string UnEscape( string str)
{
return Microsoft.JScript.GlobalObject.unescape(str);
}
|
1 2 3 4 |
string result1 = HttpUtility.UrlEncode( "张三丰" );
Console.WriteLine(result1); //
string result2 = HttpUtility.UrlDecode(result1);
Console.WriteLine(result2); // 张三丰
|
1 2 3 4 |
string path = "name=zhangsan&age=13" ;
NameValueCollection values = HttpUtility.ParseQueryString(path);
Console.WriteLine(values.Get( "name" )); // zhangsan
Console.WriteLine(values.Get( "age" )); // 13
|
1 2 3 4 5 |
string html = "<h1>张三丰</h1>" ;
string html1 = HttpUtility.HtmlEncode(html);
Console.WriteLine(html1); // <h1>张三丰</h1>
string html2 = HttpUtility.HtmlDecode(html1);
Console.WriteLine(html2); // <h1>张三丰</h1>
|
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有