/// <summary>
/// Unicode编码(汉字转换为\uxxx)
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string EnUnicode(string str)
{
StringBuilder strResult = new StringBuilder();
if (!string.IsNullOrEmpty(str))
{
for (int i = ; i < str.Length; i++)
{
strResult.Append("\\u");
strResult.Append(((int)str[i]).ToString("x"));
}
}
return strResult.ToString();
} /// <summary>
/// Unicode解码(\uxxxx转换为汉字)
/// </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[].Value, )).ToString(); });
}
/// <summary>
/// 汉字转换为Unicode编码(测试)
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string StringToUnicode(string str)
{
string result = "";
for (int i = ; i < str.Length; i++)
{
result += "&#" + (int)(str.Substring(i, ).ToCharArray()[]) + ";";
}
return result;
}

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

  1. C# \uxxx Unicode编码解码

    /// <summary> /// Unicode编码 /// </summary> /// <param name="str"></pa ...

  2. Unicode编码解码在线转换工具

    // Unicode编码解码在线转换工具 Unicode 是基于通用字符集(Universal Character Set)的标准来发展,并且同时也以书本的形式(The Unicode Standar ...

  3. Unicode 编码解码

    1. Regex.Unescape(str);返回Unicode解码,非Unicode直接返回 /// <summary>      /// 2.转为Unicode编码      /// ...

  4. C# Unicode编码解码

    public static class CommpnHelpEx { /// <summary> /// unicode编码 /// </summary> /// <pa ...

  5. ASP.NET中Url编码解码

    今天遇到Url编码解码的问题,纠结了一天的时间,结果上网一查才发现太二了我们. 同事写的代码把url用HttpUtility.UrlEncode编码和解码了,本地测试没有问题,部署到服务器上就提示转码 ...

  6. python Unicode 编码解码

    1 #将Unicode转换成普通的Python字符串:"编码(encode)" 2 unicodestring = u"Hello world" 3 utf8s ...

  7. Sql Server UniCode编码解码

    ); set @s = N'揶'; select UniCode(@s),nchar(UniCode(@s)); 在 SQL Server 中处理 Unicode 字串常数时,您必需在所有的 Unic ...

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

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

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

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

随机推荐

  1. ASP.NET Core 新建线程中使用依赖注入的问题

    问题来自博问的一个提问 .net core 多线程数据保存的时候DbContext被释放 . TCPService 通过构造函数注入了 ContentService , ContentService ...

  2. BZOJ.1312.[Neerc2006]Hard Life(分数规划 最大权闭合子图)

    BZOJ 最大密度子图. 二分答案\(x\),转为求是否存在方案满足:\(边数-x*点数\geq 0\). 选一条边就必须选两个点,所以可以转成最大权闭合子图.边有\(1\)的正权,点有\(x\)的负 ...

  3. 统一各浏览器CSS 样式——CSS Reset

    html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, ...

  4. CY7C68013 USB接口相机开发记录 - 第四天:上位机编写1

    前面学习了USB相机硬件固件.设备驱动,可以实现USB设备识别.数据发送的功能.然后,非常重要的一部分,USB设备发出的数据,我要怎么接受,怎么查看发送的数据是否是正确的.网上百度了下,大部分人都使用 ...

  5. 使用Three.js为QQ用户生成3D头像阵列

    东西其实比较简单,就是输出某一范围内QQ账号的3D头像 涉及的技术主要是Three.js的基本使用 而后通过腾讯的接口异步并发请求QQ用户头像,Canavs作图生成Texture应用在球体上 需要注意 ...

  6. Java中Iterator(迭代器)实现原理

    在Java中遍历List时会用到Java提供的Iterator,Iterator十分好用,原因是: 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结 ...

  7. PAT Basic 1008

    1008 数组元素循环右移问题 (20 分) 一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A​0​​A​1​​⋯A​N ...

  8. Mysql常用语句/group by 和 having子句

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ explain: ~~~~~~~~~~~~~~~~~ ...

  9. HTML5 学习02——新元素:canvas

    HTML5 Canvas <canvas>标签:使用脚本 (通常是JavaScript)来绘制图形——默认情况下 <canvas> 元素没有边框和内容. 在画布上(Canvas ...

  10. django之模版层(template)

    上篇主要介绍了django的MTV模型,主要介绍了视图层之路由配置系统url分发和视图层之视图函数view,本篇主要讲解MTV模型中的模版层template. 本篇导论: 模版简介 模版之变量 模版之 ...