Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove www, http/https and other strings in URL in C#

Tags:

string

c#

parsing

For Example I have this string

http://www.merriam-webster.com/dictionary/sample

What I want is to return only merriam-webster.com I'm planning to use .Replace() but I think there are better approach for this question.

like image 553
ajbee Avatar asked Dec 19 '22 16:12

ajbee


1 Answers

If you are working for Winforms then

string url = "http://www.merriam-webster.com/dictionary/sample";

UriBuilder ub = new UriBuilder(url);

MessageBox.Show(ub.Host.Replace("www.",""));

and for web,

Get host domain from URL?

like image 51
Angad Avatar answered Dec 28 '22 23:12

Angad