Skip to main content
 首页 » 编程设计

c#之如何从查询中删除所有参数的值

2024年02月24日16lexus

我有一些查询字符串看起来像 View.aspx?type=a&boo=bar&i=1

如何删除所有参数的值,使其变为 View.aspx?type=&boo=&i=

对于每个字符串参数集,都有其自己的参数组合,数量为 2-3。

编辑:如何删除除特定集之外的所有参数?

请您参考如下方法:

对于所有参数

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

跳过参数“archive”和“boo”:

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