当这看起来很简单,而且有很多关于字符串/字符/正则表达式的问题,但我找不到我需要的东西(除了另一种语言: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);
}
我try 了上述问题的解决方案(希望语法相同!)但是没有.我想先删除queryString,它可以是任意长度的,然后删除页面名称,它也可以是任意长度的.
如何从完整的URL中删除查询字符串以使测试通过?