Hi everyone can someone explain to me why he vblf character keeps getting in my string please? i use this code so i don't have to check if the http:// already exists in the string with an 'if'
url1 = "http://" + URL.replace("http://","").Split("/")(0) & strin2
the problem is the result url is like this : "http://" & vblf & 'the rest of the url can anyone explain to me why the vblf keeps getting in my string?
I would really use the right tool for the job which seems to be the Uri
class:
Dim url As String = "http://google.com/blah?foo=1"
Dim uri As Uri
If Uri.TryCreate(url, UriKind.Absolute, uri) Then
Dim schemeAndHost As String = uri.Scheme + uri.SchemeDelimiter + uri.Host
End If
Result: http://google.com
If you don't know if the url contains the protocol you could use the UriBuilder
class:
Dim url As String = "google.com/blah?foo=1"
Dim schemeAndHost As String
Dim uri As Uri = Nothing
If uri.TryCreate(url, UriKind.Absolute, uri) Then
schemeAndHost = uri.Scheme + uri.SchemeDelimiter + uri.Host
ElseIf url.Contains("/") Then
uri = New UriBuilder("http", url.Remove(url.IndexOf("/"))).Uri
schemeAndHost = uri.Scheme + uri.SchemeDelimiter + uri.Host
End If
(same result)