我想从主机名中删除计算机名,以便获得服务器名。
但我不知道怎么做。
这是我的代码:
string machineName = System.Environment.MachineName; hostinfo = Dns.GetHostEntry(str); //Fetches the name of the system in the Network (SystemName.canon.co.in) string Original = hostinfo.HostName.ToString();
现在,字符串包含以下数据:
MachineName.ServerName blah.comp.co.uk
所以我想删除 blah. 所以我剩下的就是 comp.co.uk .
blah.
comp.co.uk
有人能帮我吗?
试试这个
string Original = "blah.comp.co.uk"; string[] ss = Original.Split(".".ToCharArray(), 2); string Result = ss[1];
编辑:
string Original = "blah.comp.co.uk"; string[] ss = Original.Split(new[] {'.'}, 2); string Result = ss[1];