c# unicode 编码 中文转换 已测试
来源:互联网 发布:陈文光 清华大学 知乎 编辑:程序博客网 时间:2024/05/17 09:23
中文传参时因为编码不同经常凌乱风中,故传前编成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;
}
- c# unicode 编码 中文转换 已测试
- C# Unicode 编码转换
- C# Unicode 中文转换
- 中文转换为Unicode编码-Unicode编码转换为中文
- Java 中文 Unicode 编码转换
- Java 中文 Unicode 编码转换
- 中文到unicode编码转换
- java unicode编码 中文 转换
- C# unicode编码 中文显示
- C#批量转换unicode编码
- 编码转换(ASCII和Unicode、Unicode和中文相互转换)
- 中文与 Unicode 编码的相互转换
- JS中文字符串转换unicode编码函数
- JS中文字符串转换unicode编码函数
- native2ascii unicode编码和中文转换
- Java unicode中文编码转换和反转
- Unicode编码与中文的转换
- python3 Unicode 编码转换中文显示
- videobalance 调整一个视频流的亮度、对比度、饱和度。
- 希尔(Shell)排序的C++实现代码
- 系统无法识别移动硬盘五种可能
- QT DOM方式读取xml文件(QDomElement)
- zoj 1489 2^x mod n = 1
- c# unicode 编码 中文转换 已测试
- linux内核中的Oops
- QT读取ini配置文件(QSettings)
- Windows畸形文件操作总结
- vsftpd限制访问ip
- string类型转换为16进制数strtol
- seo_manager浅谈整形美容医院网络营销
- mongodb需要的两个工具
- excel表格技巧