[C#] 纯文本查看 复制代码
/// Unicode字符转汉字.
/// 默认处理 \u7384\u673a\u8bba\u57 ...[/quote]
感谢回答,代码贴的不是很完整.
我尝试修复后代码如下[mw_shl_code=csharp,true] /// Unicode字符转汉字.
/// 默认处理 \u7384\u673a\u8bba\u575b
/// 如果遇到 &7384 &673a &8bba &575b 请对SplitString赋值为&
/// </summary>
/// <param name="str">原始字符串</param>
/// <param name="SplitString">默认为u</param>
/// <returns></returns>
public string UnicodeString(string str, string SplitString = "u")
{
//最直接的方法Regex.Unescape(str);
if (!string.IsNullOrEmpty(str))
{
StringBuilder strResult = new StringBuilder();
string[] strlist = str.Replace("\\", "").Split(new string[] { SplitString }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < strlist.Length; i++)
{
try
{
int charCode = Convert.ToInt32(strlist[i], 16);
strResult.Append((char)charCode);
}
catch (Exception)
{
continue; //跳过转换失败的字符
}
}
return strResult.ToString();
}
return "";
}