C # How to obtain top-level (level-1) domain names,
/// <Summary> /// obtain the top-level domain name of the domain name /// </summary> /// <param name = "domain"> </param> /// <returns> </returns> public static string GetTopDomainName (string domain) {// https://www.safsd.asdfasdf.baidu.com.cn/ssssd/s/b/d/hhh.html?domain=sfsdf.com.cn&id=1 Domain = domain. trim (). toLower (); string rootDomain = ".com.cn | .gov.cn |. cn |. com |. net |. org |. so |. co |. mobi |. tel |. biz |. info |. name |. me |. cc |. TV |. asiz |. hk "; if (domain. startsWith ("http: //") domain = domain. replace ("http: //", ""); if (domain. startsWith ("https: //") domain = domain. replace ("https: //", ""); if (domain. startsWith ("www. ") domain = domain. replace ("www. "," "); // safsd.asdfasdf.baidu.com.cn/sss Sd/s/B/d/hhh.html? Domain = sfsdf.com.cn & id = 1 if (domain. indexOf ("/")> 0) domain = domain. substring (0, domain. indexOf ("/"); // safsd.asdfasdf.baidu.com.cn foreach (string item in rootDomain. split ('|') {if (domain. endsWith (item) {domain = domain. replace (item, ""); if (domain. lastIndexOf (". ")> 0) // adfasd.asdfas.cn {domain = domain. replace (domain. substring (0, domain. lastIndexOf (". ") + 1)," ");} return domain + item;} continue;} return "";}