怎么使用正则表达式替换出这个字符串 求解
原字符串
aaaa [p]1f306[/p] bbbb [p]2744[/p] cccc
方法
aaaa UnicodeToString(“1f306”) bbbb UnicodeToString(“2744“) cccc
结果字符串
aaaa {字符串1} bbbb {字符串2} cccc
方法:
public static string UnicodeToString(string srcText)
{
string dst = "";
string src = srcText;
int len = srcText.Length / 6;
for (int i = 0; i <= len - 1; i++)
{
string str = "";
str = src.Substring(0, 6).Substring(2);
src = src.Substring(6);
byte[] bytes = new byte[2];
bytes[1] = byte.Parse(int.Parse(str.Substring(0, 2), NumberStyles.HexNumber).ToString());
bytes[0] = byte.Parse(int.Parse(str.Substring(2, 2), NumberStyles.HexNumber).ToString());
dst += System.Text.Encoding.Unicode.GetString(bytes);
}
return dst;
}
------解决方案--------------------string str = @"aaaa [p]1f306[/p] bbbb [p]2744[/p] cccc";