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

后端 未结 7 1760
清酒与你
清酒与你 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; 
    }
    

提交回复
热议问题