views:

59

answers:

3

I have a number of query strings looks like View.aspx?type=a&boo=bar&i=1

How to remove all parameters' values so it would become View.aspx?type=&boo=&i=

For each string set of parameters there is it's own combination of parameters, 2-3 in number.

Edit: How to remove all parameters except specific set?

+1  A: 

You want to do this inside that page? Why not forward the page to itself without parameters? Maybe I am missing the point. Care to explain a little more?

Wim Haanstra
I'm writing my own SiteMapProvider using overriding of System.Web.XmlSiteMapProvider.FindSiteMapNode and nodes in my sitemap for being dynamic has only params' names not values
abatishchev
A: 

Use System.Uri, or System.UriBuilder

feroze
How can i use it for my task?
abatishchev
Also I need to say that System.Uri is castrated class that can do nothing with query
abatishchev
feroze
+3  A: 

For all parameters

Regex.Replace(source, "=.+?(&|$)", "=$1")

To skip parameters "archive" and "boo":

Regex.Replace(source, "(?<![?&]archive|[?&]boo)=.+?(&|$)", "=$1",
    RegexOptions.IgnoreCase)
Adam Ruth
abatishchev
Edited to skip parameters
Adam Ruth