日期:2014-05-16 浏览次数:20395 次
private string Decode(string code)
{
if (code.IndexOf("%u") > -1)
{
byte[] buffer = code.Split(new string[] { "%u" }, StringSplitOptions.RemoveEmptyEntries).Select(o => Convert.ToByte(o, 16)).ToArray();
return System.Text.Encoding.UTF8.GetString(buffer);
}
return code;
}
private string UrlDecodeUnicode(string str)
{
string[] k = str.Split('&');
string result = string.Empty;
foreach (string item in k)
{
string[] it = item.Split('=');
result += string.Format("&{0}={1}", it[0], Decode(it[1]));
}
return result.TrimStart('&');
}
ss = "page=1&f=faq&k=%u00e6%u009c%u0080%u00e6%u0097%u00a9";
ss = UrlDecodeUnicode(ss);
有BUG自己改进,如果中间加了非Unicode就会出错。。