How to remove the port number from a url string

前端 未结 8 703
清酒与你
清酒与你 2021-02-02 04:57

I have the following code snippet:

string tmp = String.Format(\"

        
8条回答
  •  渐次进展
    2021-02-02 05:36

    I would use the System.Uri for this. I have not tried, but it seems it's ToString will actually output what you want:

    var url = new Uri("http://google.com:80/asd?qwe=asdff");
    var cleanUrl = url.ToString();
    

    If not, you can combine the components of the url-members to create your cleanUrl string.

提交回复
热议问题