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

转载于:https://www.cnblogs.com/songhaipeng/archive/2012/06/01/2531124.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值