从URL得到公正的域名? [英] Get just the domain name from a URL?
问题描述
我想从一个URL字符串只提取域名。我几乎有它...我使用URI
I am trying to extract just the domain name from a URL string. I almost have it... I am using URI
我有一个字符串..我的第一个想法是使用正则表达式但后来我决定使用URI类
I have a string.. my first thought was to use Regex but then i decided to use URI class
<一个href=\"http://www.google.com/url?sa=t&source=web&ct=res&cd=1&ved=0CAgQFjAA&url=http://www.test.com/&rct=j&q=test&ei=G2phS-HdJJWTjAfckvHJDA&usg=AFQjCNFSEAztaqtkaIvEzxmRm2uOARn1kQ\">http://www.google.com/url?sa=t&source=web&ct=res&cd=1&ved=0CAgQFjAA&url=http://www.test.com/&rct=j&q=test&ei=G2phS-HdJJWTjAfckvHJDA&usg=AFQjCNFSEAztaqtkaIvEzxmRm2uOARn1kQ
我需要上述转换到google.com和google不带www
I need to convert the above to google.com and google without the www
我做了以下
Uri test = new Uri(referrer);
log.Info("Domain part : " + test.Host);
基本上,这将返回www.google.com ....我也想试试,如果可能的...因为...提到
Basically this returns www.google.com .... i would like to try and return 2 forms if possible... as mentioned...
google.com
和谷歌
google.com and google
这是可能的URI?
推荐答案
是的,这是可能的用途:
Yes, it is possible use:
Uri.GetLeftPart( UriPartial.Authority )
这篇关于从URL得到公正的域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!