如何获得一个简单的计算机名称(没有域名)在c#中的完整计算机名称?(How to get a simple computer name (without the domain name) out of

编程入门 行业动态 更新时间:2024-10-26 15:22:39
如何获得一个简单的计算机名称(没有域名)在c#中的完整计算机名称?(How to get a simple computer name (without the domain name) out of a full computer name in c#?)

我是否可以从完全限定的名称(可以带或不带域名)中获得简单的计算机名称(不含域名)? 计算机名称是否可以在其中加上点(。)符号?

(这个问题似乎正在做相反的事)

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).

更多推荐

本文发布于:2023-08-06 09:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1446718.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   计算机   如何获得   完整   简单

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!