Home >Backend Development >C++ >Is there a .NET equivalent to Path.Combine for URLs?

Is there a .NET equivalent to Path.Combine for URLs?

DDD
DDDOriginal
2025-01-20 13:21:10299browse

Is there a .NET equivalent to Path.Combine for URLs?

Merge URLs in .NET

The

Path.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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn