private static string GetSubDomain(Uri uri)
{ string host = uri.Host;string subdomain = null;
if (uri.HostNameType == UriHostNameType.Dns) {subdomain = Regex.Replace(host, "((.*)(\\..*){2})|(.*)", "$2");
}
return subdomain;}
An item to note with this is if your are looking for better performance I'd suggest creating a static Regex member variable instead of using the static Replace method as I am here.
coool, can you gimme ur template? I'm kinda finding hard to put those digg and all http://infinity-unbound.blogspot.com/
ReplyDeleteHey, thanks for the code but it doesn't behave correctly for .co.uk domains...
ReplyDeleteRegex.Replace("sales.testimonialmonkey.com", "((.*)(\\..*){2})|(.*)", "$2")
returns sales which is correct, however...
Regex.Replace("sales.testimonialmonkey.co.uk", "((.*)(\\..*){2})|(.*)", "$2")
returns sales.testimonialmonkey