Use your imagination

Friday, September 22, 2006

How to extract the subdomain from a URL in C# using regular expressions

I recently read a post with some C# code for extracting a subdomain from a URL at Mads Kristensen's blog. Since I am currently working on something where I needed to do the same I decided to share the method I came up with using a regular expression. Here it is for my own and others reference.

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.

kick it on DotNetKicks.com

Thursday, September 07, 2006

New Netscape flare shows vote and comment counts

Along the same lines as my Digg feedflare, I created a FeedBurner FeedFlare for Netscape which will show an item's vote and comment counts if it has been submitted to Netscape. Clicking the link will take you to the item on Netscape. If it has not been submitted, then clicking the link will take you to the post submission page.

Any current subscribers to my service for the Digg counts feedflare can also use this service under the same subscription. Get further details at my page to support my feedflare services. If you have any issues with the service you can let me know in the comments of this post.

Wednesday, September 06, 2006

Check out my widget at SpokenQuotes.com!

I've been neglecting this blog lately to work on some other projects I've got going on. One of which I recently unleashed on the public. It's a Yahoo widget that speaks stock quotes and news. I created it to allow myself to be able to work on other software projects while doing some stock trading at the same time. I just enter the stock symbols that I am currently in or want to track and the widget runs in the background letting me hear when the price changes and by how much. It also tracks news for each symbol and speaks new headlines when they come in. I also added a charting function that pulls charts from Yahoo Finance on a timed interval so if I want I can watch the stock movement on a chart. I use it by wearing a set of wireless headphones, then when I need or want to get up and away from my desk I can still hear the market action;)

I made a website to support the widget which I also hope to build a community around by adding features to the site and widget like being able to share portfolios and talk to others who are tracking the same stocks. I built the site on top of Drupal. It is my first site based on this CMS/Framework and I am very happy with how easy it was to throw together and modify for my use. If you want to give the widget a try you can download it from the site at SpokenQuotes.com. I'd love your feedback!