How to pull the server name from a UNC

前端 未结 5 840
借酒劲吻你
借酒劲吻你 2021-02-05 16:34

Would anyone be able to tell me how to pull the server name out of a UNC?

ex.

//servername/directory/directory

Edit : I apologize but it looks like I nee

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 16:49

    How about Uri:

    Uri uri = new Uri(@"\\servername\d$\directory");
    string[] segs = uri.Segments;
    string s = "http://" + uri.Host + "/" + 
        string.Join("/", segs, 2, segs.Length - 2) + "/";
    

提交回复
热议问题