开发者

How to remove all parameters' values from query

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 num开发者_JAVA技巧ber.

Edit: How to remove all parameters except specific set?


For all parameters

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

To skip parameters "archive" and "boo":

Regex.Replace(source, "(?<![?&]archive|[?&]boo)=.+?(&|$)", "=$1",
    RegexOptions.IgnoreCase)


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?


Use System.Uri, or System.UriBuilder

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜