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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM