Insert variable into middle of url

こ雲淡風輕ζ 提交于 2019-12-14 03:58:08

问题


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


回答1:


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)



回答2:


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.



来源:https://stackoverflow.com/questions/23872754/insert-variable-into-middle-of-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!