Assuming the following url:
Dim nvc As NameValueCollection = HttpUtility.ParseQueryString(http://localhost/Index.aspx?A=23&A=7&A=1)
How can I remove a specific instance of A from a NameValueCollection?
I can add an additional entry
nvc.Add("A", 10)
But can only seem to remove all instances
nvc.Remove("A")
I would prefer not to use string hacks.
Try out this method, string manipulation is not abused (I think).
The method extracts the Query part, selects the values of the Key specified except the values to remove, then rebuilds the Query using the UriBuilder.Query property (which can be set), finally returning a new formed
Uri, missing the removed Key-Value pairs.You could also just get the
Uri.Query, split and rebuild the same way.More string manipulations, though.