我有一个字符串,我想将其转换为字符串索引数组以方便使用。
以下是我的期望和结果。
有人可以指导我完成这个吗?
细绳: Dim QueryResponse = "TVShow=Adventure Time" & vbCrLf & "Color=Red"
大批:
Array
(
["TVShow"] => "Adventure Time"
["Color"] => "Red"
)
我目前的代码: Dim result() As String = QueryResponse.Split({vbCrLf}, StringSplitOptions.RemoveEmptyEntries)
当前代码数组:
Array
(
[0] => "TVShow=Adventure Time"
[1] => "Color=Red"
)
想对这个提出一些意见,谢谢!
使用字典代替数组
Dim dictionary1 As New Dictionary(Of String, String)
Dim result() As String = QueryResponse.Split({vbCrLf}, StringSplitOptions.RemoveEmptyEntries)
Dim res1 As String = result(0)
Dim res2 As String = result(1)
'Split res1 and res2 into arrays using '=' as delimeter
Dim res1s() As String = Split(res1,"=")
Dim res2s() As String = Split(res2,"=")
dictionary1.Add(res1(0),res1(1))
dictionary1.Add(res2(0),res2(1))
要访问字典条目,请使用
Dim pair As KeyValuePair(Of String, String)
For Each pair In dictionary1
You can access the values here using `pair.key` and `pair.value`
'Eg Label1.Text = pair.key or Console.WriteLine(pair.value)
Next
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句