2

how can I get the protocol and the domain form a string?

I think I should use regex for this?

Is this correct or is there a better solution?

If this is correct what should the regex code look like?

E.g.

I have the following URL: http://www.somedomain.com/page/subpage

And I would like to get: http://www.somedomain.com

Some more example URL's: https://www.somedomain.com/page/subpage (https://www.somedomain.com) or http://somedomain.com/page/subpage (http://somedomain.com) or http://test.domain.com/page/subpage (http://test.domain.com)

Thanks!

1 Answer 1

4

Start with:

Dim myUri as new Uri("http://www.somedomain.com/page/subpage")

and myUri will have all the answers for you. Domain property, protocol property etc etc. Off the top of my head, I think you need this:

Dim baseUri as String = myUri.GetLeftPart(UriPartial.Authority)

-Oisin

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.