How to remove the port number from a url string

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

I have the following code snippet:

string tmp = String.Format(\"

        
相关标签:
8条回答
  • 2021-02-02 05:47

    You can also use the properties of URIBuilder for this, it has properties for outputting an url the way you want

    0 讨论(0)
  • 2021-02-02 05:50
    UriBuilder u1 = new UriBuilder( "http://www.example.com:80/dir/?query=test" );
    u1.Port = -1;
    string clean = u1.Uri.ToString();
    

    Setting the Port property to -1 on UriBuilder will remove any explicit port and implicitly use the default port value for the protocol scheme.

    0 讨论(0)
提交回复
热议问题