C#中编码转换开发笔记

中文转Unicode:HttpUtility.UrlEncodeUnicode(string str);
转换后中文格式:"%uxxxx"  举例:"柳_abc123"  转换结果是:"%u67f3_abc123"

 

Unicode转中文1:HttpUtility.UrlDecode(string str);
str格式:"%uxxxx" ,举例:"%u67f3_abc123"

 

Unicode转中文2:Regex.Unescape(string str);
str格式:"\uxxxx" ,举例:"\u67f3_abc123"

 

1.window.escape()与HttpUtility.UrlEncodeUnicode()编码格式一样:将一个汉字编码为%uxxxx格式
不会被window.escape编码的字符有:@ _ - . * / +  这与http://www.w3school.com.cn/js/jsref_escape.asp上的解释不符合

2.window.encodeURIComponent()与HttpUtility.UrlEncode()编码格式一样:将一个汉字编码为%xx%xx%xx的格式

不会被window.encodeURIComponent编码的字符有:'()*-._!~ 这与http://www.w3school.com.cn/js/jsref_encodeURIComponent.asp解释相符合

不会被HttpUtility.UrlEncode编码的字符有:'()*-._!相比较而言,HttpUtility.UrlEncode比window.encodeURIComponent多一个 ~ 编码

3.不会被window.encodeURI编码的字符有:-_.!*();/?:@&=$,# 与encodeURIComponent对比,发现encodeURI不对:;/?:@&=+$,#这些用于分隔 URI 组件的标点符号进行编码

Asp.Net编码与JS编码的区别:

1. 不会被HttpUtility.UrlEncodeUnicode编码的字符与不会被HttpUtility.UrlEncode编码的字符一样,而escape和encodeURIComponent不编码的字符不一样

2. HttpUtility.UrlEncode和HttpUtility.UrlEncodeUnicode会对/编码,而escape和encodeURIComponent会对/编码,encodeURI不会对/编码

3. HttpUtility.UrlEncode()和HttpUtility.UrlEncodeUnicode()会把空格编码为 +,而escape,encodeURIComponent,encodeURI都会将空格编码为%20

posted on 2012-06-01 17:29  宋海鹏  阅读(3426)  评论(0编辑  收藏  举报

导航