vb.net在2个字符之前获取文本并使用它

时间:2014-02-16 14:58:42

标签: vb.net

有人可以帮助我如何使用数据?

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

我想以某种方式使用这个数据:

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

,下一个是

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

然后

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

那么如何使用“=”和“”之间的数据?

1 个答案:

答案 0 :(得分:2)

所以基本上你有一个包含由空格分隔的键/值对的字符串。您可以使用Split方法提取必要的信息:

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