c# unicode 编码 中文转换 已测试(转)
中文传参时因为编码不同经常凌乱风中,故传前编成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 编码 中文转换 已测试(转)的更多相关文章
- unicode 编码在线转换--javascript
// unicode 编码在线转换工具--javascript 本人在网上搜索,看到有使用javascript做unicode编码转换的,感觉很好玩,所以拿来使用的. 这个功能有目前测试了两种: 1) ...
- .Net(c#)汉字和Unicode编码互相转换
{"Tilte": "\u535a\u5ba2\u56ed", "Href": "http://www.cnblogs.com&q ...
- PHP解码unicode编码中文字符代码示例
在抓取某网站数据,结果在数据包中发现了一串编码的数据:"......\u65b0\u6d6a\u5fae\u535a......", 这其实是中文被unicode编码后了的数据,想 ...
- Unicode与中文转换工具类方法(转)
/* * 中文转unicode编码 */ public static String gbEncoding(final String gbString) { char[] utfBytes = gbSt ...
- js字符串与Unicode编码互相转换
).toString() "597d" 这段代码的意思是,把字符'好'转化成Unicode编码,toString()就是把字符转化成16进制了 看看charCodeAt()是怎么个 ...
- .Net(c#)汉字和Unicode编码互相转换实例
{"name": "\u676d\u5dde", "href": "www.baidu.com"} 经常遇到这样内容的j ...
- C#怎么判断字符是不是汉字 汉字和Unicode编码互相转换
判断一个字符是不是汉字通常有三种方法,第1种用 ASCII 码判断(在 ASCII码表中,英文的范围是0-127,而汉字则是大于127,根据这个范围可以判断),第2种用汉字的 UNICODE 编码范围 ...
- PHP解码unicode编码中文字符代码
function replace_unicode_escape_sequence($match) { return mb_convert_encoding(pack('H*', $match[1]), ...
- unicode 编码在线转换工具
字符串 unideo的16进制值
随机推荐
- 数据库、Java与Hibernate数据类型对照
数据类型对照表: 标准SQL数据类型 Java数据类型 Hibernate数据类型 TINYINT byte.java.lang.Byte byte SMALLINT short.java.lang. ...
- Educational Codeforces Round 11C. Hard Process two pointer
地址:http://codeforces.com/contest/660/problem/C 题目: You are given an array a with n elements. Each el ...
- Oracle数据安全(四)j角色管理
一.角色管理的概述 1.角色的概念 为了简化数据库权限的管理,在Oracle数据库中引入了角色的概念.所谓的角色就是一系列相关权限的集合. 2.角色的特点 在数据库中,角色的名称必须是唯一的,不能与用 ...
- $python数据分析基础——初识matplotlib库
基本用法 import numpy as np import matplotlib.pyplot as plt # 年份 year = [1950,1970,1990,2010] # 全球总人口(单位 ...
- npm国内镜像设置
http://cnodejs.org/topic/4f9904f9407edba21468f31e
- [ufldl]Supervised Neural Networks
要实现的部分为:forward prop, softmax函数的cost function,每一层的gradient,以及penalty cost和gradient. forwad prop forw ...
- poj1694
/*给出一棵树的描述 第一行输入t,代表案例的个数 第二行一个n代表这棵树有n个节点 接下来n行第一个数是节点的编号,根节点编号为1,然后第二个数是节点的个数,如果为0那就没子节点,否则输入节点的 编 ...
- SVN使用—高级用法
一.SVN分支 Branch 选项会给开发者创建出另外一条线路.当有人希望开发进程分开成两条不同的线路时,这个选项会非常有用. 情景: 比如项目 demo 下有两个小组,svn 下有一个 trunk ...
- SQL-ALTER-change和modify区别
ALTER 对于列的应用: 1.更改列名 格式:CHANGE old_col_name new_col_name column_definition 保留old和new列名 ...
- 课堂测试Mysort
课上没有做出来的原因 因为自己平时很少动手敲代码,所以在自己写代码的时候往往会比较慢,而且容易出现一些低级错误,再加上基础没有打牢,对于老师课上所讲的知识不能及时的理解消化,所以可能以后的课上测试都要 ...