当这看起来很简单并且在字符串/字符/正则表达式上有很多问题时,我感到有些愚蠢,但是我找不到我真正需要的东西(除了另一种语言:在特定点之后删除所有文本)。
我有以下代码:
[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中删除查询字符串,以便此测试通过?
/
?