主要代码部分如下:
1
using System.Text.RegularExpressions;
2
3
/// <summary>
4
/// 将Unicode转找为Character
5
/// </summary>
6
/// <param name="str">原字符串</param>
7
/// <returns></returns>
8
private string Unicode2Character(string str)
9
{
10
string text = str;
11
string strPattern = "(?<code>\\\\u[A-F0-9]{4})";
12
do
13
{
14
Match m = Regex.Match(text, strPattern, RegexOptions.IgnoreCase);
15
if (m.Success)
16
{
17
string strValue = m.Groups["code"].Value;
18
int i = System.Int32.Parse(strValue.Substring(2, 4), System.Globalization.NumberStyles.HexNumber);
19
char ch = Convert.ToChar(i);
20
text = text.Replace(strValue, ch.ToString());
21
}
22
else
23
{
24
break;
25
}
26
}
27
while(true);
28
29
return text;
30
}
using System.Text.RegularExpressions;2

3
/// <summary>4
/// 将Unicode转找为Character5
/// </summary>6
/// <param name="str">原字符串</param>7
/// <returns></returns>8
private string Unicode2Character(string str)9
{10
string text = str;11
string strPattern = "(?<code>\\\\u[A-F0-9]{4})";12
do13
{14
Match m = Regex.Match(text, strPattern, RegexOptions.IgnoreCase);15
if (m.Success)16
{17
string strValue = m.Groups["code"].Value;18
int i = System.Int32.Parse(strValue.Substring(2, 4), System.Globalization.NumberStyles.HexNumber);19
char ch = Convert.ToChar(i);20
text = text.Replace(strValue, ch.ToString());21
}22
else23
{24
break;25
}26
}27
while(true);28

29
return text;30
}工具源码下载: down


浙公网安备 33010602011771号