Possible Duplicate:
c#: Get just the domain name from a URL?
C# : Getting exact domain name from any URL
I am trying to remove the top level domains extension from a given URL.
Example www.google.com, www.google.co.uk
I can extract the host and using Uri class, and can strip away the "www.".
I can also strip the .com, .org or any other extension as long as it is 3 characters.
How would I go about removing extension such as .co.uk or any URL that contains something different than the standard.
I really just need to extract the Top level domain ex ("google" or "maps.google").
Any help on this would be greatly appreciated.
Here is a code snippet of how I extract the last item of Uri object.
public static string Test(Uri uri)
{
if (!uri.HostNameType.Equals(UriHostNameType.Dns) || uri.IsLoopback)
return string.Empty; // or throw an exception
return uri.Host.Split('.').Last();
}