日期:2014-05-18 浏览次数:20988 次
Server.UrlEncode(string s)--对s进行Url编码: Server.UrlDncode(string s)--对s进行Url解码:
------解决方案--------------------
参考
------解决方案--------------------
我觉得百度的这种编码方式是自己写的,LZ完全可以自己实现
我这里有个是最所以字符都进行编码的,LZ参考下
//编码 public static string Encode(this string str) { string codeword = ""; byte[] by = Encoding.Default.GetBytes(str); foreach (byte b in by) { codeword = codeword + "%" + b.ToString("X"); } return codeword; } //解码 public static string Decode(this string str) { string[] strlist = str.Split(new string[] { "%" }, StringSplitOptions.RemoveEmptyEntries); byte[] by = new byte[strlist.Length]; for (int i = 0; i < strlist.Length; i++) { string temp = strlist[i]; int inttemp = ToInt(AnyToTen(temp, 16)); if (inttemp > 0) by[i] = byte.Parse(inttemp.ToString()); else return ""; } return Encoding.Default.GetString(by); }
------解决方案--------------------
额..不好意思,ToInt是转换成整数的方法,AnyToTen(temp, 16)是16进制转换成10进制的,LZ可以用其他方法代替
------解决方案--------------------
private static long Test(string hexStr) { char[] charList = hexStr.ToCharArray(); long result = 0; for (int i = 0; i < charList.Length; i++) { result += HexChar2Dec(charList[charList.Length - 1 - i]) * Power(16, i); } return result; }
------解决方案--------------------
public static string Escape(string str)
{
StringBuilder sb = new StringBuilder();
foreach (char c in str)
{
sb.Append((Char.IsLetterOrDigit(c) || c == '-' || c == '_' || c == ' ' || c == '/' || c == '.') ? c.ToString() : Uri.HexEscape(c));
}
return sb.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Escape("ray()"));
}
或者直接引用Microsoft.JScript.dll
Microsoft.JScript.GlobalObject.escape("ray()")
------解决方案--------------------
学习啦,谢谢大家