DaE
DaE

Reputation: 189

Insert variable into middle of url

how could I insert a variable into the middle of a URL using vb.net?

e.g.

Dim ver As String = "variable"

http://testurl.co.uk/folder/next_folder/" & ver & "/test.exe

(not sure if this is correct above)

Note: I know how to set a variable but not sure how to insert into the middle of a URL

Upvotes: 1

Views: 2601

Answers (2)

Paul Michaels
Paul Michaels

Reputation: 16685

You could do that (as @SysDragon has pointed out, you need to store the result in a variable). Another alternative would be:

Dim ver As String = "variable"
Dim url As String = String.format("http://testurl.co.uk/folder/next_folder/{1}/test.exe", ver)

It probably doesn't matter for something as trivial as this, but strings are immutable, so doing:

Dim myString as String = "a" & "b" & "c" 

effectively destroys and recreates the string twice. StringBuilder (which I believe string.format uses internally) prevents this.

Upvotes: 1

SysDragon
SysDragon

Reputation: 9888

Almost, I think you want this:

Dim ver As String = "variable"
Dim url As String = "http://testurl.co.uk/folder/next_folder/" & ver & "/test.exe"

To browse the url in the form do something like this:

Dim wb1 As New Net.WebBrowser()

Form1.Controls.Add(wb1)
wb1.Navigate(url)

Upvotes: 0

Related Questions