zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    019. Remove Nth Node From End of List
    021.Merge Two Sorted Lists
    自定义starter
    servlet里面转发与重定向
    贪婪模式与非贪婪模式
    localstack 线程隔离
    Algorithm & Data structure
    some interview question
    阿里-菜鸟国际-出口大团队招新啦
    JDK8漫谈——集合更强大
  • 原文地址:https://www.cnblogs.com/songhaipeng/p/2531124.html
Copyright © 2011-2022 走看看