日期:2014-05-18 浏览次数:20780 次
/// <summary> /// 将Unicode转换为汉字 /// </summary> /// <param name="name">要转换的字符串</param> /// <returns></returns> public string UnicodeToGB(string text) { MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))"); if (mc != null && mc.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (Match m2 in mc) { string v = m2.Value; string word = v.Substring(2); byte[] codes = new byte[2]; int code = Convert.ToInt32(word.Substring(0, 2), 16); int code2 = Convert.ToInt32(word.Substring(2), 16); codes[0] = (byte)code2; codes[1] = (byte)code; sb.Append(Encoding.Unicode.GetString(codes)); } return sb.ToString(); } else { return text; } }