Reputation: 93
I have this url: https://uk.soccerway.com/national/italy/serie-a/20172018/regular-season/r42011/?ICID=TN_02_01_02
I want remove ?ICID=TN_02_01_02
, of couse this string is dynamic so I can't use .Replace()
method, any idea?
Upvotes: 1
Views: 2909
Reputation: 38850
You can use the Uri
class to parse the URL. It allows you to get only up to a specific part using the GetLeftPart method:
public static string GetUriWithoutQuery(string url)
{
var uri = new Uri(url);
return uri.GetLeftPart(UriPartial.Path);
}
Upvotes: 1
Reputation: 299
Use Uri try create (https://msdn.microsoft.com/en-us/library/ms131572(v=vs.110).aspx) to create a Uri object.
Then with that Uri object take the "Query" property which will contain the entire query string.
And use "AbsolutePath" to get the URL without the query string.
Upvotes: 2