str = System.Text.RegularExpressions.Regex.Replace(str, @"\\x(\w{2})", (a) =>
{
return Convert.ToChar(Convert.ToInt32(a.Value.Replace("\\x", ""),16)).ToString();
});
调用接口时用到的, 接口返回带有\x 前缀的16进制编码字符 使用正则替换掉.
如何编码???
using System;
public class Program
{
public static void Main()
{
char x1=':';
char x2='!';
Console.WriteLine(String.Format(@"\x{0:x2}", (ushort)x1));
Console.WriteLine(String.Format(@"\x{0:x2}", (ushort)x2));
}
}
输出:
\x3a
\x21
版权声明:本文为qq934021379原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。