/// <summary> /// 过滤掉地址里无需要的参数 /// </summary> /// <param name="url">地址</param> /// <param name="paramname">参数名</param> /// <returns></returns> public string FilterUrlParam(string url, string paramname) { string str = ""; if (url.ToLower().IndexOf("?") != -1) { str = url.Substring(url.ToLower().IndexOf("?") + 1); } else { return url; } string[] arr = new string[] { }; string returnurl = ""; if (url.ToLower().IndexOf(‘&‘) != -1) { arr = str.Split(‘&‘); for (int i = 0; i < arr.Length; i++) { if (i < arr.Length) { if (arr[i].Split(‘=‘)[0].ToLower() != paramname) { returnurl = returnurl + arr[i].Split(‘=‘)[0] + "=" + arr[i].Split(‘=‘)[1] + "&"; } } } return url.Substring(0, url.IndexOf(‘?‘)) + "?" + returnurl.Substring(0, returnurl.Length - 1); } else { arr = str.Split(‘=‘); if (arr[0].ToLower() == paramname) { return url.Substring(0, url.IndexOf(‘?‘)); } else { return url; } } }
时间: 2024-10-28 21:10:54