Click here to Skip to main content
15,905,593 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I have a urlfor example as below

ex:
VB
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_...


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

Thanks,
Prasant
Posted
Comments
Deependra Khangarot 20-Mar-13 0:58am    
Hi Prasant,

Can you provide the project type, Web or windows.
User CP 20-Mar-13 1:18am    
HI Deep,Its a web project type
Sergey Alexandrovich Kryukov 20-Mar-13 1:20am    
I'm just curious: do you think is someone did not do it before, this person should not be trusted in solution of this super sophisticated problem? :-)
And why do you thing that Amazon is a host name?
—SA

1 solution

C#
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];
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900