关于\Uxxxx 的解码问题

WM_JAWIN 2009-05-27 12:46:13
\u5218\u5a1f 像这样的UTF8编码,怎么还原成汉字? WinFrom
...全文
397 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
SQL77 2009-05-27
  • 打赏
  • 举报
回复

string [] mychar = new string [] { "\u5218", "\u5a1f" };


foreach (string ch in mychar )
{
Console.WriteLine(ch);
}
he_8134 2009-05-27
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Globalization;
namespace ConsoleApplication16
{
class Program
{
static void Main(string[] args)
{
string str = @"\u5218\u5a1f";
str = Regex.Replace(
str,
@"\\u([\dabcdefABCDEF]{4})",
m => ((char)int.Parse(m.Groups[1].Value, NumberStyles.HexNumber)).ToString()
);
Console.Write(str);
}
}
}

zgke 2009-05-27
  • 打赏
  • 举报
回复
string _Temp = @"\u5218\u5a1f";
MessageBox.Show(GetString(_Temp));


private string GetString(string p_Value)
{
string _ReturnText = "";
string[] _ValueList = p_Value.Split(new char[] { '\\','u'},StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i != _ValueList.Length; i++)
{
char _ValueChar = Convert.ToChar(Convert.ToUInt16(_ValueList[i], 16));
_ReturnText += _ValueChar.ToString();
}
return _ReturnText;
}
starj1 2009-05-27
  • 打赏
  • 举报
回复
十六进制字符串转为16位十进制整数楼主会吧?然后再转为字符就可以了。

2楼的代码只能在写程序行的时候有用,没法在运行时即时转换吧?
wuyq11 2009-05-27
  • 打赏
  • 举报
回复
System.Text.Encoding.GetEncoding("gb2312")

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧