日期:2014-05-18 浏览次数:20758 次
class Program { static void Main(string[] args) { string tt = ttemp(); Console.WriteLine(tt); } private static string ttemp() { byte[] b = System.Text.Encoding.Unicode.GetBytes("京东商城"); string str = ""; for (int i = 0; i < b.Length; i = i + 2) { str += "\\u" + string.Format("%{0:X}", b[i + 1]) + string.Format("%{0:X}", b[i]); } str = str.Replace("%", "").ToLower(); //Console.WriteLine(str); return str; } }
------解决方案--------------------
string sh = HttpUtility.UrlEncodeUnicode("京东商城").Replace(@"%u",@"\u");
------解决方案--------------------
输出结果没有问题啊
\u4eac\u4e1c\u5546\u57ce
------解决方案--------------------
var source = "京东商城"; var result = source.Aggregate(string.Empty, (current, c) => current + string.Format("{0}{1:x4}", @"\u", (int) c)); Console.WriteLine(result);