中文传参时因为编码不同经常凌乱风中,故传前编成unicode码来过度是一个不错的解决方法

/// <summary>

/// 中文转unicode
        /// </summary>
        /// <returns></returns>
        public static string unicode_0(string str)
        {
            string outStr = "";
            if (!string.IsNullOrEmpty(str))
            {
                for (int i = 0; i < str.Length; i++)
                {
                    outStr += "/u" + ((int)str[i]).ToString("x");
                }
            }
            return outStr;
        }
        /// <summary>
        /// unicode转中文
        /// </summary>
        /// <returns></returns>
        public static string unicode_1(string str)
        {
            string outStr = "";  
            if (!string.IsNullOrEmpty(str))  
            {  
                string[] strlist = str.Replace("/","").Split('u');  
                try  
                {  
                    for (int i = 1; i < strlist.Length; i++)  
                    {  
                        //将unicode字符转为10进制整数,然后转为char中文字符  
                        outStr += (char)int.Parse(strlist[i], System.Globalization.NumberStyles.HexNumber);  
                    }  
                }  
                catch (FormatException ex)  
                {  
                    outStr = ex.Message;  
                }  
            }
            return outStr;

}

/// <summary>
        /// unicode转中文(符合js规则的)
        /// </summary>
        /// <returns></returns>
        public static string unicode_js_1(string str)
        {
            string outStr = "";
            Regex reg = new Regex(@"(?i)\\u([0-9a-f]{4})");
            outStr = reg.Replace(str, delegate(Match m1)
            {
                return ((char)Convert.ToInt32(m1.Groups[1].Value, 16)).ToString();
            });
            return outStr;
        }
        /// <summary>
        /// 中文转unicode(符合js规则的)
        /// </summary>
        /// <returns></returns>
        public static string unicode_js_0(string str)
        {
            string outStr = "";
            string a = "";
            if (!string.IsNullOrEmpty(str))
            {
                for (int i = 0; i < str.Length; i++)
                {
                    if (Regex.IsMatch(str[i].ToString(), @"[\u4e00-\u9fa5]")) { outStr += "\\u" + ((int)str[i]).ToString("x"); }
                    else { outStr += str[i]; }
                }
            }
            return outStr;
        }

转自:http://blog.csdn.net/lbx541575387/article/details/6710815

c# unicode 编码 中文转换 已测试(转)的更多相关文章

  1. unicode 编码在线转换--javascript

    // unicode 编码在线转换工具--javascript 本人在网上搜索,看到有使用javascript做unicode编码转换的,感觉很好玩,所以拿来使用的. 这个功能有目前测试了两种: 1) ...

  2. .Net(c#)汉字和Unicode编码互相转换

    {"Tilte": "\u535a\u5ba2\u56ed", "Href": "http://www.cnblogs.com&q ...

  3. PHP解码unicode编码中文字符代码示例

    在抓取某网站数据,结果在数据包中发现了一串编码的数据:"......\u65b0\u6d6a\u5fae\u535a......", 这其实是中文被unicode编码后了的数据,想 ...

  4. Unicode与中文转换工具类方法(转)

    /* * 中文转unicode编码 */ public static String gbEncoding(final String gbString) { char[] utfBytes = gbSt ...

  5. js字符串与Unicode编码互相转换

    ).toString() "597d" 这段代码的意思是,把字符'好'转化成Unicode编码,toString()就是把字符转化成16进制了 看看charCodeAt()是怎么个 ...

  6. .Net(c#)汉字和Unicode编码互相转换实例

    {"name": "\u676d\u5dde", "href": "www.baidu.com"} 经常遇到这样内容的j ...

  7. C#怎么判断字符是不是汉字 汉字和Unicode编码互相转换

    判断一个字符是不是汉字通常有三种方法,第1种用 ASCII 码判断(在 ASCII码表中,英文的范围是0-127,而汉字则是大于127,根据这个范围可以判断),第2种用汉字的 UNICODE 编码范围 ...

  8. PHP解码unicode编码中文字符代码

    function replace_unicode_escape_sequence($match) { return mb_convert_encoding(pack('H*', $match[1]), ...

  9. unicode 编码在线转换工具

    字符串 unideo的16进制值  

随机推荐

  1. Flash本地共享对象 SharedObject

    以下内容是对网上一些资料的总结 Flex SharedObject 介绍(转自http://www.eb163.com/club/thread-3235-1-1.html): Flash的本地共享对象 ...

  2. Mootools遮罩层练习(原为网上的jquery写法)

    <html > <head> <meta charset="utf-8" /> <title>mootools 遮罩层</ti ...

  3. ArcGIS COM Exception 0x80040228

    问题:  string shpDir = Path.GetDirectoryName(shpfile);             string shpfilename = Path.GetFileNa ...

  4. cmd命令 启动 和关闭sql服务

    (1)在操作系统的任务栏中单击“开始”菜单,选择“运行”命令,在下拉列表框中输入“cmd”命令,单击“确定”按钮. (2)输入如下命令,即可通过SQL Server命令行启动.停止或暂停的服务. SQ ...

  5. 【HTML5校企公益课】第三天

        1.上午2D.旋转变色的... 基本思路就是先写静态画面然后添加动画. <!--告诉浏览器该文件为网页格式--> <html> <!--网页的头部标签--> ...

  6. Boot-Repair&usb_repair

    https://help.ubuntu.com/community/Boot-Repair https://askubuntu.com/questions/500647/unable-to-mount ...

  7. jQuery动态网址标签

    在线演示 本地下载

  8. 【React Native开发】React Native进行签名打包成Apk

    转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/50525976 本文出自:[江清清的博客] (一)前言 [好消息]个人 ...

  9. Routing and Action Selection in ASP.NET Web API

    https://exceptionnotfound.net/using-http-methods-correctly-in-asp-net-web-api/ The algorithm ASP.NET ...

  10. ls存在的文件,不能操作

    bash-4.2# pwd/oracle/product/10.2.0/db_1/network/adminbash-4.2# lssqlnet.ora                 libnrad ...