110,535
社区成员
发帖
与我相关
我的任务
分享
System.Web.HttpUtility.UrlEncode("love中国", Encoding.Unicode)
怎么结果会是:l%00o%00v%00e%00-N%fdV
public static string ToUnicode(string str)
{
byte[] bts = Encoding.Unicode.GetBytes(str);
string r = "";
for (int i = 0; i < bts.Length; i += 2) r += "%u" + bts[i + 1].ToString("X").PadLeft(2, '0') + bts[i].ToString("X").PadLeft(2, '0');
return r;
}
System.Console.Write(ToUnicode("中国"));
static string EncodeString(string str)
{
string ret = string.Empty;
foreach (char ch in str)
{
if (ch <= 0xff)
ret += ch;
else
{
byte[] bytes = BitConverter.GetBytes(ch);
ret += string.Format("%u{0:X}{1:X}", bytes[1], bytes[0]);
}
}
return ret;
}