sharkyenergy
sharkyenergy

Reputation: 4173

split url in url and path, VB.NET

i have an application where users submit URL's. these urls may be anything, a few examples are here:

ftp://ftp.mysite.com
ftp.mysiste.com
mysite.com
mysite.de
ftp.mysite.it/somepath/somotherfolder
ftp://ftp.anysiste.com/
ftp://ftp.anysiste.org/somefolder/

i need to split these sites in the URL and the PATH. here is the result of the above:

ftp.mysite.com ---- /
ftp.mysiste.com ---- /
mysite.com ---- /
mysite.de ---- /
ftp.mysite.it ---- /somepath/somotherfolder
ftp.anysiste.com ---- /
ftp.anysiste.org ---- /somefolder/

is there a safe way to split these like this? or do i have to make it via search/split functions?

Upvotes: 0

Views: 884

Answers (1)

Ry-
Ry-

Reputation: 224913

Use the System.Uri class.

Dim uri As New Uri("ftp://ftp.anysiste.org/somefolder/")
uri.AbsolutePath '/somefolder/
uri.Host         'ftp.anysiste.org
uri.Scheme       'ftp

Upvotes: 1

Related Questions