0

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?

user3781458
  • 71
  • 1
  • 2
  • 8
  • the sample url dosn't matter, but if it can help, i only get this when i use the data from a csv file (that my same application has created), so now for each line of a file i do a replace(vblf,nothing) before i get the data in it – user3781458 Jul 02 '14 at 15:38

1 Answers1

1

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)

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • thank you, even if i don't have to use this right now since i discovered the source of the problem, but i might still need it later – user3781458 Jul 02 '14 at 15:41