A
Adam Tibi
Hello,
I want to get the right most name of the a domain name, for example:
if the domain is www.myweb.com , I want to get myweb.com
something.myweb.com --> myweb.com
www.myweb.com.au --> myweb.com.au
something.myweb.com.au --> myweb.com.au
www.myweb.tv --> myweb.tv
www.something.myweb.net --> myweb.net
my.test.myweb.ca --> myweb.ca
I want to know if there is a general rule, code or article regarding this
issue.
I tried the following code, but I am not convinced, because it is not
generic
public static string GetDomainName(string serverName ) {
if(!serverName.Contains(".")) {
return serverName.ToLower();
}
if(serverName.EndsWith(".co.uk")) {
return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
".co.uk".Length - 1) + 1).ToLower();
}
if(serverName.EndsWith(".com") || serverName.EndsWith(".net") ||
serverName.EndsWith(".org")) {
return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
5) + 1).ToLower();
}
return null;
}
Does any one have a better solution?
Adam Tibi
I want to get the right most name of the a domain name, for example:
if the domain is www.myweb.com , I want to get myweb.com
something.myweb.com --> myweb.com
www.myweb.com.au --> myweb.com.au
something.myweb.com.au --> myweb.com.au
www.myweb.tv --> myweb.tv
www.something.myweb.net --> myweb.net
my.test.myweb.ca --> myweb.ca
I want to know if there is a general rule, code or article regarding this
issue.
I tried the following code, but I am not convinced, because it is not
generic
public static string GetDomainName(string serverName ) {
if(!serverName.Contains(".")) {
return serverName.ToLower();
}
if(serverName.EndsWith(".co.uk")) {
return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
".co.uk".Length - 1) + 1).ToLower();
}
if(serverName.EndsWith(".com") || serverName.EndsWith(".net") ||
serverName.EndsWith(".org")) {
return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
5) + 1).ToLower();
}
return null;
}
Does any one have a better solution?
Adam Tibi