我需要您的幫助。我想從我的C#應用程序中的字符串拆分域名。 對此有任何想法。如何從字符串獲取域名
如:string strURL="http://stackoverflow.com/questions";
,我需要一個像 域名輸出:stackoverflow.com
我需要您的幫助。我想從我的C#應用程序中的字符串拆分域名。 對此有任何想法。如何從字符串獲取域名
如:string strURL="http://stackoverflow.com/questions";
,我需要一個像 域名輸出:stackoverflow.com
這應該工作。
新的URI( 「http://stackoverflow.com/questions」).DnsSafeHost
您可以使用正則表達式做....
string domainName = string.Empty;
string strURL="http://stackoverflow.com/questions";
Regex rg = new Regex("://(?<host>([a-z\\d][-a-z\\d]*[a-z\\d]\\.)*[a-z][-a-z\\d]+[a-z])");
if (rg.IsMatch(strURL))
{
domainName = rg.Match(strURL).Result("${host}");
}
則domainName給域名稱.....
謝謝阿卡什,請檢查此網址,如www.google.co.in/somthing ...像子域也。 – 2012-03-06 09:36:16
此問題已被問過1000次。在你的搜索能力上付出一點努力。 – 2012-03-06 08:03:31
快速谷歌給了這個許多可行的答案。 – Corbin 2012-03-06 08:03:41
嗨juergen,請參考我的鏈接找到最好的解決方案 – 2012-03-06 09:26:21