[转]c#Unicode转成汉字
/// <summary>
/// 把四个字符长度的Unicode转成对应的汉字
/// </summary>
/// <param name="str">长度是4的Unicode</param>
/// <returns>对应的汉字,若转换出错则返回原字符串</returns>
private string Unicode2UnitCharacter(string str)
{
if (str.Length != 4)
{
return str;
}
try
{
byte code = System.Convert.ToByte(str.Substring(0, 2), 16);
byte code2 = System.Convert.ToByte(str.Substring(2), 16);
return System.Text.Encoding.Unicode.GetString(new byte[] { code2, code });
}
catch (Exception)
{
return str;
}
/// 把四个字符长度的Unicode转成对应的汉字
/// </summary>
/// <param name="str">长度是4的Unicode</param>
/// <returns>对应的汉字,若转换出错则返回原字符串</returns>
private string Unicode2UnitCharacter(string str)
{
if (str.Length != 4)
{
return str;
}
try
{
byte code = System.Convert.ToByte(str.Substring(0, 2), 16);
byte code2 = System.Convert.ToByte(str.Substring(2), 16);
return System.Text.Encoding.Unicode.GetString(new byte[] { code2, code });
}
catch (Exception)
{
return str;
}