【发布时间】:2010-04-18 01:15:26
【问题描述】:
当这看起来很简单并且有大量关于字符串/字符/正则表达式的问题时,我感觉有点愚蠢,但我找不到我需要的东西(除了另一种语言:Remove All Text After Certain Point)。
我有以下代码:
[Test]
public void stringManipulation()
{
String filename = "testpage.aspx";
String currentFullUrl = "http://localhost:2000/somefolder/myrep/test.aspx?q=qvalue";
String fullUrlWithoutQueryString = currentFullUrl.Replace("?.*", "");
String urlWithoutPageName = fullUrlWithoutQueryString.Remove(fullUrlWithoutQueryString.Length - filename.Length);
String expected = "http://localhost:2000/somefolder/myrep/";
String actual = urlWithoutPageName;
Assert.AreEqual(expected, actual);
}
我尝试了上述问题中的解决方案(希望语法相同!)但没有。我想先删除可以是任意长度的 queryString,然后再删除可以是任意长度的页面名称。
如何从完整 URL 中删除查询字符串以使该测试通过?
【问题讨论】: