How to remove the port number from a url string

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

I have the following code snippet:

string tmp = String.Format(\"

        
8条回答
  •  长发绾君心
    2021-02-02 05:24

    var url = "http://google.com:80/asd?qwe=zxc#asd";
    var regex = new Regex(@":\d+");
    var cleanUrl = regex.Replace(url, "");
    

    the solution with System.Uri is also possible but will be more bloated.

提交回复
热议问题