如何从 UNC 中提取服务器名称 [英] How to pull the server name from a UNC
本文介绍了如何从 UNC 中提取服务器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我如何从 UNC 中提取服务器名称?
Would anyone be able to tell me how to pull the server name out of a UNC?
例如
//服务器名/目录/目录
//servername/directory/directory
我道歉,但看起来我需要澄清一个错误:路径实际上更像是:
Edit : I apologize but it looks like I need to clarify a mistake: the path actually is more like:
//服务器名/d$/目录
我知道这可能会改变一些事情
I know this might change things a little
推荐答案
Uri
怎么样:
Uri uri = new Uri(@"\\servername\d$\directory");
string[] segs = uri.Segments;
string s = "http://" + uri.Host + "/" +
string.Join("/", segs, 2, segs.Length - 2) + "/";
这篇关于如何从 UNC 中提取服务器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文