/// <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. RMQ问题 [luogu 3865]

    原题地址 ST表模板题,尝试用单点修改线段树. 原本以为线段树会被卡掉,但是还是险过了.实践证明,快速读入很有用. #include<bits/stdc++.h> using namesp ...

  2. [tem]最长上升子序列

    Longest Increasing Subsequence(LIS) 一个美丽的名字 非常经典的线性结构dp [朴素]:O(n^2) d(i)=max{0,d(j) :j<i&& ...

  3. GDOI2017爆炸记

    100种方法教你爆零.. 总结 其实这一次比赛除了三个sb的错误还是收获到了很多的.. 起码自己已经知道自己有进队的实力 不足的地方很大 主要是脑子不太好使,题目要不只能拿最暴力的分要不就能a 看了很 ...

  4. redis(五)

    发布订阅 发布者不是计划发送消息给特定的接收者(订阅者),而是发布的消息分到不同的频道,不需要知道什么样的订阅者订阅 订阅者对一个或多个频道感兴趣,只需接收感兴趣的消息,不需要知道什么样的发布者发布的 ...

  5. 【数论】Factors of Factorial @upcexam6503

    问题 G: Factors of Factorial 时间限制: 1 Sec  内存限制: 128 MB提交: 57  解决: 33[提交][状态][讨论版][命题人:admin] 题目描述 You ...

  6. python每日笔记

    9.28 查看python包路径: sys.path 9.4  sorted高级用法: >>> class Student: def __init__(self, name, gra ...

  7. GMA Round 1 双曲线与面积

    传送门 双曲线与面积 P是双曲线$\frac{x^2}{1471^2}-\frac{y^2}{1372^2}=1$上的一个动点,现在过P作一条直线与该双曲线的两条渐近线相交于A.B两点,且|AP|=| ...

  8. Servlet(5)—ServletRequest接口和ServletResponse接口

    ServletRequest接口: 使用ServletRequest接口创建对象,用于使客户端请求信息对Servlet可用,创建的对象作为参数传递之Servlet的Service() ServletR ...

  9. RMQ(Range MinimumQuery)问题之ST算法

    ST算法------是用来求解给定区间RMQ的最值,本文以最小值为例 ST算法分为两部分 离线预处理(nlogn):运用DP思想,用于求解区间最值,并保存到一个二维数组中. 在线查询 (O(1)):对 ...

  10. pygame 笔记-2 模仿超级玛丽的弹跳

    在上一节的基础上,结合高中物理中的匀加速直线运动位移公式 ,就能做出类似超级玛丽的弹跳效果. import pygame pygame.init() win = pygame.display.set_ ...