标签:
/// <summary> /// URL编码 /// </summary> /// <param name="Source"></param> /// <param name="Encod">是否UTF8</param> /// <param name="toUpper">默认到大写</param> /// <returns></returns> public static string URLEncod(string Source, Encoding Encod, bool toUpper = true) { if (toUpper) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < Source.Length; i++) { string t = Source[i].ToString(); string k = HttpUtility.UrlEncode(t, Encod); if (t == k) sb.Append(t); else sb.Append(k.ToUpper()); } return sb.ToString(); } else return HttpUtility.UrlEncode(Source, Encod); } /// <summary> /// URL解码 /// </summary> /// <param name="Source"></param> /// <param name="Encod">是否UTF8</param> /// <returns></returns> public static string URLDecode(string Source, Encoding Encod) { return HttpUtility.UrlDecode(Source, Encod); }
标签:
原文地址:http://www.cnblogs.com/milest/p/4787566.html