Reputation: 389
I want to trim the machine name from my Hostname so that I can get the server name.
But I'm not able to figure out how.
This is my code:
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();
Now the string contains the data like:
MachineName.ServerName
blah.comp.co.uk
So I want to remove blah.
from the string so that what I am left with is comp.co.uk
.
Can anyone help me out with it?
Upvotes: 0
Views: 137
Reputation: 10285
try this
string Original = "blah.comp.co.uk";
string[] ss = Original.Split(".".ToCharArray(), 2);
string Result = ss[1];
EDIT:
string Original = "blah.comp.co.uk";
string[] ss = Original.Split(new[] {'.'}, 2);
string Result = ss[1];
Upvotes: 1