Asp.Net \uxxx Unicode编码解码
/// <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编码解码的更多相关文章
- C# \uxxx Unicode编码解码
/// <summary> /// Unicode编码 /// </summary> /// <param name="str"></pa ...
- Unicode编码解码在线转换工具
// Unicode编码解码在线转换工具 Unicode 是基于通用字符集(Universal Character Set)的标准来发展,并且同时也以书本的形式(The Unicode Standar ...
- Unicode 编码解码
1. Regex.Unescape(str);返回Unicode解码,非Unicode直接返回 /// <summary> /// 2.转为Unicode编码 /// ...
- C# Unicode编码解码
public static class CommpnHelpEx { /// <summary> /// unicode编码 /// </summary> /// <pa ...
- ASP.NET中Url编码解码
今天遇到Url编码解码的问题,纠结了一天的时间,结果上网一查才发现太二了我们. 同事写的代码把url用HttpUtility.UrlEncode编码和解码了,本地测试没有问题,部署到服务器上就提示转码 ...
- python Unicode 编码解码
1 #将Unicode转换成普通的Python字符串:"编码(encode)" 2 unicodestring = u"Hello world" 3 utf8s ...
- Sql Server UniCode编码解码
); set @s = N'揶'; select UniCode(@s),nchar(UniCode(@s)); 在 SQL Server 中处理 Unicode 字串常数时,您必需在所有的 Unic ...
- C# 如何将字符串形式的” \\u1234 “ 为 “ \u1234” 的unicode编码解码为中文
using System.Text.RegularExpressions; decodedStr = Regex.Unescape(escapeUnicodeStr);
- PHP解码unicode编码中文字符代码示例
在抓取某网站数据,结果在数据包中发现了一串编码的数据:"......\u65b0\u6d6a\u5fae\u535a......", 这其实是中文被unicode编码后了的数据,想 ...
随机推荐
- ContextRefreshedEvent事件使用注意事项(Spring)
0 概述ContextRefreshedEvent 事件会在Spring容器初始化完成会触发该事件.我们在实际工作也可以能会监听该事件去做一些事情,但是有时候使用不当也会带来一些问题. 1 防止重复触 ...
- Ural2110 : Remove or Maximize
设最大的数为$w$,若$n>k+\log w$,那么显然所有$1$都可以保留,否则现在$n\leq k+\log w$. 如果$w\leq 100000$,那么可以DP,设$f[i][j]$表示 ...
- .net 4.0 中的特性总结(一):dynamic
在新版本的C#中,dynamic关键词是一个很重要的新特性,现在你可以创建动态对象并在运行时再决定它的类型.而且.net 4.0为CLR加入了一组为动态语言服务的运行时环境,称为DLR(Dynamic ...
- centos 7 之nginx
环境信息 [root@node1 ~]# cat /etc/redhat-release CentOS Linux release (Core) [root@node1 ~]# uname -r -. ...
- Yii Cache 缓存的使用
我的缓存组件配置在config\main.php文件,配置如下: 'components' => [ 'cache' => [ 'class' => 'yii\caching\Fil ...
- 3ds max学习笔记-- 动画
栗子:若要使茶壶从a点运动到b点,是需要动画实现的:动画与传统意义的移动不同,与时间是存在关系的: 时间线,时间滑条: [时间配置]按钮: 弹出面板: 动画时间轴默认时间是从0帧开始100结束:总长度 ...
- weak_ptr_c++11
unique_ptr 替代了原来的auto_ptr,指向对象具有唯一性,即同一时间只能有unique_ptr指向给定对象(和auto_ptr不同是禁止拷贝语义,通过移动语义替代) unique_ptr ...
- js生成1-100不重复的随机数及生成10个1-100不重复的随机数
//生成1-100不重复的随机数 var count=100; var a=new Array(); for(var i=0;i<100;i++){ a[i]=i+1; } a.sort(fun ...
- python 可迭代对象
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1. 可以用for 进行迭代的,一般都是可迭代对象: ...
- Python3 与 NetCore 基础语法对比(List、Tuple、Dict、Set专栏)
Jupyter最新版:https://www.cnblogs.com/dotnetcrazy/p/9155310.html 在线演示:http://nbviewer.jupyter.org/githu ...