No host names can contain a period ( Wikipedia link and RFC 952 (see "ASSUMPTIONS") and RFC 1123 ). This is a separator between the host name and the domain name. Therefore you can just do
string fullName = "foobar.domain"; string hostName = fullName.Substring(0, fullName.IndexOf('.'));
(With proper error checking, of course, for the case when "fullName" is actually not a full name).
source share