/// <summary>
/// 获取url替换url参数
/// </summary>
/// <param name="url"></param>
/// <param name="ParamText">key</param>
/// <param name="ParamValue">Value</param>
/// <returns></returns>
public string BuildUrl(string url, string ParamKey, string ParamValue)
{
Regex reg = new Regex(string.Format("{0}=[^&]*", ParamKey), RegexOptions.IgnoreCase);
Regex reg1 = new Regex("[&]{2,}", RegexOptions.IgnoreCase);
string _url = reg.Replace(url, "");
//_url = reg1.Replace(_url, "");
if (_url.IndexOf("?") == -1)
_url += string.Format("?{0}={1}", ParamKey, ParamValue);//?
else
_url += string.Format("&{0}={1}", ParamKey, ParamValue);//&
_url = reg1.Replace(_url, "&");
_url = _url.Replace("?&", "?");
return _url;
}
找了好久的url替换,找了一个c#可用的,记录下来
最新推荐文章于 2023-05-13 13:48:54 发布