Asp.Net \uxxx Unicode编码解码

/// <summary>
        /// Unicode编码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string EnUnicode(string str)
        {
            StringBuilder strResult = new StringBuilder();
            if (!string.IsNullOrEmpty(str))
            {
                for (int i = 0; i < str.Length; i++)
                {
                    strResult.Append("\\u");
                    strResult.Append(((int)str[i]).ToString("x"));
                }
            }
            return strResult.ToString();
        }

        /// <summary>
        /// Unicode解码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string DeUnicode(string str)
        {
            //最直接的方法Regex.Unescape(str);
            Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
            return reg.Replace(str, delegate(Match m) { return ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString(); });
        }

原文地址:https://www.cnblogs.com/webapi/p/10659370.html

时间: 2024-08-29 06:59:10

Asp.Net \uxxx Unicode编码解码的相关文章

PHP 汉字 特殊字符 UNICODE 编码 解码 高性能简洁实现方案

网上,针对汉字.特殊字符的UNICODE 编码.解码实现,方法诸多,但是大多是复制粘贴,没有新意! PHP UNICODE 汉字 编码: var_dump(json_encode('2018 ABC 我是中国人!网站:http://my.oschina.net/cart/')); 上述就实现了PHP中对汉字.特殊字符的 UNICODE 编码! 多么easy! 上面会输出: string(96) ""2018 ABC \u6211\u662f\u4e2d\u56fd\u4eba\uff0

Unicode 编码解码

1. Regex.Unescape(str);返回Unicode解码,非Unicode直接返回 /// <summary>      /// 2.转为Unicode编码      /// </summary>      /// <param name="str"></param>      /// <returns></returns>  public static  string ToUnicode(string

Unicode编码解码在线转换工具

Unicode 是基于通用字符集(Universal Character Set)的标准来发展,并且同时也以书本的形式(The Unicode Standard,目前第五版由Addison-Wesley Professional出版,ISBN-10: 0321480910)对外发表. 2006年7月的最新版本的 Unicode 是5.0版本. 2005年3月31日推出的Unicode 4.1.0 .另外,5.0 Beta于2005年12月12日推出,5.2版本(unicode standard)

ASP.NET中Url编码解码

今天遇到Url编码解码的问题,纠结了一天的时间,结果上网一查才发现太二了我们. 同事写的代码把url用HttpUtility.UrlEncode编码和解码了,本地测试没有问题,部署到服务器上就提示转码失败,查看问题发现转码的时候把“+”转成了“%”,但是解码的时候把“%”装换成了“ ”空格,最后上网查了下很多网友都遇到过这种问题, 最后把HttpUtility.UrlEncode替换成了一下的方式就OK了. var email="15586757225"; string after =

Sql Server UniCode编码解码

declare @s varchar(50); set @s = N'揶'; select UniCode(@s),nchar(UniCode(@s)); 在 SQL Server 中处理 Unicode 字串常数时,您必需在所有的 Unicode 字串前加上大写字母 N 做为前置词,N 前置词代表的是 SQL-92 标淮中的国家语言,且必须为大写.如果您没有在 Unicode 字串常数前面加上 N 做为前置词,则 SQL Server 会在使用字串前,先将其转换成目前资料库的非 Unicode

C# 如何将字符串形式的” \\u1234 “ 为 “ \u1234” 的unicode编码解码为中文

using System.Text.RegularExpressions; decodedStr = Regex.Unescape(escapeUnicodeStr);

js中文转Unicode编码与解码

中文转为unicode 编码: function encodeUnicode(str) { var res = []; for (var i = 0; i < str.length; i++) { res[i] = ( "00" + str.charCodeAt(i).toString(16) ).slice(-4); } return "\\u" + res.join("\\u"); } unicode编码解码为中文: function

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

在抓取某网站数据,结果在数据包中发现了一串编码的数据:"......\u65b0\u6d6a\u5fae\u535a......", 这其实是中文被unicode编码后了的数据,想解码出中文来.解决方案:方案A(稳定版+推荐): function replace_unicode_escape_sequence($match) { return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE'); } $name

PHP解码unicode编码的中文字符

问题背景:晚上在抓取某网站数据,结果在数据包中发现了这么一串编码的数据:"......\u65b0\u6d6a\u5fae\u535a......www.jinyuanbao.cn", 这其实是中文被unicode编码后了的数据,我现在就是想解码出中文来,疯狂的google之后,发现很多人贴出了如下的函数,不过我发现根本不好使....如何解码unicode编码的字符?[好使] - PHP网站开发 - [开源与分享]每日最新博客在置顶博客之后: 如何解码unicode编码的字符?[好使]