路径组合 https://msdn.microsoft.com/en-us/library/system.io.path.combine%28v=vs.110%29.aspx很方便,但是 .NET 框架中有类似的功能吗URLs http://en.wikipedia.org/wiki/Uniform_resource_locator?
我正在寻找这样的语法:
Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")
这将返回:
"http://MyUrl.com/Images/Image.jpg"
Uri https://learn.microsoft.com/en-us/dotnet/api/system.uri有一个构造函数应该为您执行此操作:new Uri(Uri baseUri, string relativeUri)
这是一个例子:
Uri baseUri = new Uri("http://www.contoso.com");
Uri myUri = new Uri(baseUri, "catalog/shownew.htm");
编者注:请注意,此方法不会按预期工作。在某些情况下它可以剪切部分baseUri。查看评论和其他答案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)