111,113
社区成员




public static string UnicodeToGB(string content)
{
Regex objRegex = new Regex(@"\\u([a-zA-Z0-9]{4});", RegexOptions.IgnoreCase);//&#(?<UnicodeCode>[\\d]{5})
Match objMatch = objRegex.Match(content);
StringBuilder sb = new StringBuilder(content);
while (objMatch.Success)
{
string code = Convert.ToString(Convert.ToInt32(objMatch.Result("${UnicodeCode}"), 16), 16);
byte[] array = new byte[2];
array[0] = (byte)Convert.ToInt32(code.Substring(2), 16);
array[1] = (byte)Convert.ToInt32(code.Substring(0, 2), 16);
sb.Replace(objMatch.Value, Encoding.Unicode.GetString(array));
objMatch = objMatch.NextMatch();
}
return sb.ToString();
}
public static string UnicodeToGB(string content)
{
Regex objRegex = new Regex(@"\\u(?<UnicodeCode>[\w]{4})", RegexOptions.IgnoreCase);//&#(?<UnicodeCode>[\\d]{5})||@"\\u([a-zA-Z0-9]{4});"
Match objMatch = objRegex.Match(content);
StringBuilder sb = new StringBuilder(content);
while (objMatch.Success)
{
string code = Convert.ToString(Convert.ToInt32(objMatch.Result("${UnicodeCode}"), 16), 16);
byte[] array = new byte[2];
array[0] = (byte)Convert.ToInt32(code.Substring(2), 16);
array[1] = (byte)Convert.ToInt32(code.Substring(0, 2), 16);
sb.Replace(objMatch.Value, Encoding.Unicode.GetString(array));
objMatch = objMatch.NextMatch();
}
return sb.ToString();
}
string str = @"<h1 id=folder_view_heading>\u6536\u4ef6\u7bb1</h1><span>\u6240\u6709\u90ae\u4ef6</span>";
Regex reg = new Regex(@"\\u\w{4}");
MatchCollection mc = reg.Matches(str);
foreach (Match ma in mc)
{
string s = Regex.Unescape(ma.Value.ToString()).ToString();
//.......
}
void Main()
{
string test = @"<h1 id=folder_view_heading>\u6536\u4ef6\u7bb1</h1><span>\u6240\u6709\u90ae\u4ef6</span>";
Console.WriteLine(Regex.Unescape(test));
//<h1 id=folder_view_heading>收件箱</h1><span>所有邮件</span>
}