Get specific subdomain from URL in foo.bar.car.com

后端 未结 7 1729
清酒与你
清酒与你 2020-11-30 10:19

Given a URL as follows:

foo.bar.car.com.au

I need to extract foo.bar.

I came across the following code :

pr         


        
相关标签:
7条回答
  • 2020-11-30 10:53
    private static string GetSubDomain(Uri url)
    {
        if (url.HostNameType == UriHostNameType.Dns)
        {
    
            string host = url.Host;   
            String[] subDomains = host.Split('.');
            return subDomains[0] + "." + subDomains[1];
         }
        return null; 
    }
    
    0 讨论(0)
提交回复
热议问题