我是否可以从完全限定的名称(可以带或不带域名)中获得简单的计算机名称(不含域名)? 计算机名称是否可以在其中加上点(。)符号?
(这个问题似乎正在做相反的事)
Can I get just a simple computer name (without the domain name) from a fully qualified name (can be with or without a domain name)? Is it possible for a computer name to have a dot (.) sign in it?
(this question seems to be doing the reverse)
最满意答案
没有主机名不能包含一个点(引用维基百科和RFC 952 (见“假设”)和RFC 1123 )。 它是主机名和域名之间的分隔符。 所以你可以简单地做
string fullName = "foobar.domain"; string hostName = fullName.Substring(0, fullName.IndexOf('.'));(当然,正确的错误检查,对于“fullName”实际上不是全名的情况)。
No hostnames cannot contain a dot (reference Wikipedia and RFC 952 (see "ASSUMPTIONS") and RFC 1123). It is the delimiter between the hostname and the domainname. So you can simply do
string fullName = "foobar.domain"; string hostName = fullName.Substring(0, fullName.IndexOf('.'));(With proper error checking of course, for the case that "fullName" is not actually a fullname).
更多推荐
发布评论