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
Release: 2025-01-20 13:21:10
Original
331 people have browsed it

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:

Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")
Copy after login

The return value is:

<code>"http://MyUrl.com/Images/Image.jpg"</code>
Copy after login
The

Uri class provides a constructor for this purpose: new Uri(Uri baseUri, string relativeUri). For example:

Uri baseUri = new Uri("http://www.contoso.com");
Uri myUri = new Uri(baseUri, "catalog/shownew.htm");
Copy after login

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 of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template