2

I want to get domain name without the "http" and "www".

For example:

 https://www.google.com => google.com

 http://www.google.com => google.com

 www.google.com => google.com

Attempts made:

               Dim myUri As New Uri(url)
                Dim host = myUri.Host
                Dim host1 = myUri.AbsolutePath
                Dim host2 = myUri.AbsoluteUri
                Dim host3 = myUri.Authority
                Dim host4 = myUri.DnsSafeHost
                Dim host5 = myUri.Fragment
                Dim host6 = myUri.HostNameType

None of this works for me. Can some one guide me how to achieve above in C# or VB.Net (preferrable VB.Net)

Unbreakable
  • 7,776
  • 24
  • 90
  • 171

1 Answers1

8

The closest you can get is through the Uri.Host property. After that you need to use string manipulation like:

myUri.Replace("www.", "")

See https://msdn.microsoft.com/en-us/library/system.uri.host(v=vs.100).aspx

automaton
  • 1,972
  • 5
  • 25
  • 40