Home >Backend Development >C++ >Is there a .NET equivalent to Path.Combine for URLs?
Merge URLs in .NET
ThePath.Combine
function makes it easy to merge file paths, but is there a similar function for URLs in the .NET Framework? Consider the following syntax requirements:
<code class="language-csharp">Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")</code>
The return value is:
<code>"http://MyUrl.com/Images/Image.jpg"</code>The
Uri
class provides a constructor for this purpose: new Uri(Uri baseUri, string relativeUri)
. For example:
<code class="language-csharp">Uri baseUri = new Uri("http://www.contoso.com"); Uri myUri = new Uri(baseUri, "catalog/shownew.htm");</code>
Note: Keep in mind that this method does not always work as expected. In some cases, it may clip parts of the base URI. See comments and other responses for more information.
The above is the detailed content of Is there a .NET equivalent to Path.Combine for URLs?. For more information, please follow other related articles on the PHP Chinese website!