First let me explain what I mean by properly: I found many methods out there, but most of them will end up using string manipulations and things like that. I'd like to know if there is a simple way to do such using built in functions.
So far I change the parameters of a URL
with a string myNewValue
:
Uri myUri = new Uri(URL);
var qs = HttpUtility.ParseQueryString(myUri.Query);
qs["ParameterName"] = myNewValue;
This does work pretty well. Now I'd like to get my URL
back in a string
with those new parameters. What is the proper way to do it? Something like getting the URL
without patterns from my original string and merging the obtained parameters?
Note: So far I'm able to do it with Substring
and such, I just find it "unclean" when one start to find chars in a string to Substring
stuff from it.
How I do is simple. From my original URL I substring up to the "?
", then I combine with qs.ToString()