一、URL编码
/// <summary> /// URL编码 (=、?、& 不参于编码) /// </summary> /// <param name="str"></param> /// <returns></returns> public static string HtmlUrlEncode(string str) { string result = string.Empty; result = System.Web.HttpUtility.UrlEncode(str); result = result.Replace("%3d", "=").Replace("%3f", "?").Replace("%26", "&"); return result; }
二、URL解码
/// <summary> /// URL解码 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string HtmlUrlDecode(string str) { string result = string.Empty; result = System.Web.HttpUtility.UrlDecode(str); result = result.Replace("%3d", "=").Replace("%3f", "?").Replace("%26", "&"); return result; }
注:在WinForm中记得引用 System.Web 命名空间。