Path.Combine is handy, but is there a similar function in the .NET framework for URLs?
I'm looking for syntax like this:
Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")
which would return:
"http://MyUrl.com/Images/Image.jpg"
Path.Combine is handy, but is there a similar function in the .NET framework for URLs?
I'm looking for syntax like this:
Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")
which would return:
"http://MyUrl.com/Images/Image.jpg"
You use
Uri.TryCreate( ... )
:Will return:
There's already some great answers here. Based on mdsharpe suggestion, here's an extension method that can easily be used when you want to deal with Uri instances:
And usage example:
This will produce http://example.com/subpath/part1/part2
Well, I just concatenate two strings and use regular expressions to do the cleaning part.
So, you can use it like this:
I created this function that will make your life easier:
It works for URLs as well as normal paths.
Usage:
Here is my approach and I will use it for myself too: