本文介绍了仅从Url获​​取主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有一个urlfor示例如下



ex:

Hi I have a urlfor example as below

ex:

http://g-ecx.images-amazon.com
http://z-ecx.images-amazon.com
http://ecx.images-amazon.com
http://completion.amazon.com
http://client-log.amazon.com
http://www.amazon.com/184-8984226-0489751
http://www.amazon.com/access
http://www.amazon.com/gp/product/B0083PWAPW/ref=kin_dev_gw_dual_t/184-8984226-04...
http://www.amazon.com/gp/product/B007OZNZG0/ref=kin_dev_gw_dual_c/184-8984226-04...
http://www.amazon.com/gp/prime/signup/videos/ref=nav_menu_video_redirect_combine...
http://www.amazon.com/gp/prime/signup/videos/ref=nav_menu_video_pic_redirect_com...
http://www.amazon.com/gp/prime/signup/videos/ref=nav_menu_shipping_redirect_comb...
http://www.amazon.com/gp/prime/signup/videos/ref=nav_menu_shipping_pic_redirect_...





现在我想从这些网址中只检索域名即亚马逊。任何人都可以这之前??



谢谢,

Prasant



Now i want to retrieve only Domain name i.e amazon out of these urls.Can any one did this before??

Thanks,
Prasant

推荐答案

var uri = new Uri("http://www.amazon.com/184-8984226-0489751");
string[] splitHostName = uri.Host.Split('.');
if (splitHostName.Length >= 2)
    {
       string HostName = splitHostName[splitHostName.Length - 2];
    }


这篇关于仅从Url获​​取主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 11:08