【发布时间】:2012-02-06 06:54:23
【问题描述】:
给定以下示例“字符串”:
- somePage.aspx?id=20&name=brian&token=1234
- somePage.aspx?id=20&token=1234&name=brian
- somePage.aspx?token=1234&id=20&name=brian
我想在所有情况下都删除令牌的名称/值对,所以我只剩下:
- somePage.aspx?id=20&name=brian
- somePage.aspx?id=20&name=brian
- somePage.aspx?id=20&name=brian
注意:由于各种原因,我不能使用 Uri 类。
是否有一个单一的正则表达式或字符串函数可以做到这一点?
【问题讨论】:
-
I cannot use the Uri class for various reason例如? -
可能在类库中添加
System.Web引用实在是太臃肿了?我遇到过。 -
强制包含
System.Web会导致他的应用程序对于只安装了 .Net 4.0 客户端配置文件(这是许多 W7 机器上的 .Net 的默认安装)的任何人中断,所以它使避免使用System.Web以减少部署问题。 -
@ean5533 - Uri 不在 System.Web 中,它在 System - msdn.microsoft.com/en-us/library/system.uri.aspx
-
我不能使用 Uri 类的原因是因为我正在处理绝对路径和各种相对路径(“../”、/SomeFolder/ 等)的组合并且能够可能无法得出真正的路径。
标签: c# asp.net regex c#-4.0 .net-4.0