Extract base URl from a string in c#?

前端 未结 5 2037
情书的邮戳
情书的邮戳 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:34

    If you want to get all 3 of them in a list here is something you could also start with there are so many options you can do once you get the Host Name also if you are wanting everything past the .com use the AbsolutePath method

    var uriList = new List()
                {
                    "http://www.mysite.com/mypage/default.aspx",
                    "http://www.mysite.edu/mypage/default.aspx",
                    "http://www.mysite.eu/mypage/default.aspx"
                };
            var holdList = new List();
            foreach (var uriName in uriList)
            {
                Uri uri = new Uri(uriName);
                holdList.Add(uri.Host);
            }
    

提交回复
热议问题