我需要您的帮助。我想从我的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