Extract base URl from a string in c#?

前端 未结 5 2035
情书的邮戳
情书的邮戳 2021-02-03 21:31

I am currently working on a project with .NET 1.1 framework and I am stuck at this point. I have a string like \"http://www.example.com/mypage/default.aspx\" or it might be \"ht

5条回答
  •  鱼传尺愫
    2021-02-03 21:41

    var builder = new UriBuilder("http://www.example.com/mypage/default.aspx");
    builder.Path = String.Empty;
    var baseUri = builder.Uri;
    var baseUrl = baseUri.ToString();
    // http://www.example.com/
    

提交回复
热议问题