title: Get specific subdomain from URL in foo.bar.car.com
body: <p>Given a URL as follows:</p>
  
  <p><code>foo.bar.car.com.au</code></p>
  
  <p>I need to extract <code>foo.bar</code>.</p>
  
  <p>I came across the following code :</p>
  
  <pre><code>private static string GetSubDomain(Uri url)
  {
      if (url.HostNameType == UriHostNameType.Dns)
      {
          string host = url.Host;
          if (host.Split('.').Length &gt; 2)
          {
              int lastIndex = host.LastIndexOf(".");
              int index = host.LastIndexOf(".", lastIndex - 1);
              return host.Substring(0, index);
          }
      }         
      return null;     
  }
  </code></pre>
  
  <p>This gives me like <code>foo.bar.car</code>. I want foo.bar. Should i just use split and take 0 and 1?</p>
  
  <p>But then there is possible wwww.</p>
  
  <p>Is there an easy way for this?</p>