http://www.myluoluo.com/unicodetogb2312.love

你是否遇到类似于:\u5355\u4f4d之类的让人纠结的字符?

一个JS文件中一堆一堆的全都是这种,分析起来很吃力?

/// <summary>
/// 将Unicode编码转换为汉字字符串
/// </summary>
/// <param name="str">Unicode编码字符串</param>
/// <returns>汉字字符串</returns>
public static string ToGB2312(string str)
{
string tempStr = str;
MatchCollection mc = Regex.Matches(str, @"\\u([\w]{2})([\w]{2})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
byte[] bts = new byte[];
foreach (Match m in mc)
{
bts[] = (byte)int.Parse(m.Groups[].Value, NumberStyles.HexNumber);
bts[] = (byte)int.Parse(m.Groups[].Value, NumberStyles.HexNumber);
tempStr = tempStr.Replace(m.Value, Encoding.Unicode.GetString(bts));
}
return tempStr;
}
04-25 14:31