Path.Combine for URLs?

前端 未结 30 2534
不思量自难忘°
不思量自难忘° 2020-11-22 14:28

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.         


        
30条回答
  •  礼貌的吻别
    2020-11-22 15:25

    I found that the Uri constructor flips '\' into '/'. So you can also use Path.Combine, with the Uri constructor.

     Uri baseUri = new Uri("http://MyUrl.com");
     string path = Path.Combine("Images", "Image.jpg");
     Uri myUri = new Uri(baseUri, path);
    

提交回复
热议问题