user3293636
user3293636

Reputation: 13

vb.net Get text after before 2 character and use it

can someone help me how can I use the datas?

Dim String as String = "thing=lol1 thing=lol2 thing=lol3 ..."

I want to use this datas somehow like this:

For i As Integer
Dim webClient1 As New System.Net.WebClient
Dim result As String = webClient1.DownloadString("http://pr2hub.com/submit_rating.php?level_id=" + lol1)
Next

and the next is

Dim result As String = webClient1.DownloadString("http://pr2hub.com/submit_rating.php?level_id=" + lol2)

then

Dim result As String = webClient1.DownloadString("http://pr2hub.com/submit_rating.php?level_id=" + lol3)

So how can I use the datas between "=" and " "?

Upvotes: 0

Views: 379

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

So basically you have a string containing key/value pairs separated by spaces. You could use the Split method to extract the necessary information:

Dim result as String = "thing=lol1 thing=lol2 thing=lol3 ..."
Dim tokens = result.Split(New String() {" "}, StringSplitOptions.RemoveEmptyEntries)
For Each token As String In tokens
    Dim kvp = token.Split(New String() {"="}, StringSplitOptions.RemoveEmptyEntries)
    If kvp.Length > 1 Then
        Dim key as String = kvp(0)
        Dim value as String = kvp(1)
        ' Do something with the key and value here
    End If
Next

Upvotes: 2

Related Questions