Question How do I manipulate Website address to remove subdomain if there is one?

htconex

Member
Joined
May 16, 2012
Messages
7
Programming Experience
5-10
How do I manipulate Website address to remove sub-domain if there is one?

For example change en.Wikipedia.org
to
Wikipedia.org


I know I can use
Dim domain As String = Url.Items(i).Split("/"c)(2)

to modify a website address to just show domain
but I'd rather sub-domains didn't show up either.

So Google.com
rather than mail.Google.com
 
Thank you for giving me some information but i've already looked into that.
But if anyone else can help me with this, that would be great :)
 
or you can use the Uri class, for example like this:
    Function GetDomain(u As Uri) As String
        If u.HostNameType <> UriHostNameType.Dns Then Return String.Empty
        Dim parts = u.Host.Split("."c)
        If parts.Length > 1 Then
            Return String.Join(".", parts, parts.Length - 2, 2)
        Else
            Return parts(0)
        End If
    End Function
 
I would normally call a function with a string i.e. http://mail.google.com/
How do i do this with the above function as I get the error

Error 1 Value of type 'String' cannot be converted to 'System.Uri'. C:\Users\HtcOneX\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 13 19 WindowsApplication1
 
Back
Top