我正在尝试为逗号分隔的字符串中的字符串赋值。 请参阅下面的错误代码。
Dim newArray As String() = "M2-1_,IR,Pass,499V,>10G,5.0s"
results = Split(newArray, ",", -1, vbBinaryCompare)
Dim results1 As String = newArray(0)
Dim results2 As String = newArray(1)
Dim results3 As String = newArray(2)
ListBox1.Items.Add(results1)
ListBox1.Items.Add(results2)
ListBox1.Items.Add(results3)
我目前的结果是:
M
2
-
我想要结果:
M2-1_
IR
Pass
感谢!!!!!
答案 0 :(得分:2)
如果你只想要前3:
Dim newArray As String = "M2 - 1_,IR,Pass,499V,>10G,5.0s"
ListBox1.Items.AddRange(newArray.Split(",").Take(3).ToArray)
如果你想要全部:
Dim newArray As String = "M2 - 1_,IR,Pass,499V,>10G,5.0s"
ListBox1.Items.AddRange(newArray.Split(","))
答案 1 :(得分:0)
Dim newArray = "M2-1_,IR,Pass,499V,>10G,5.0s"
Dim results() As String = newArray.Split(",")
ListBox1.Items.Add(results1(0))
ListBox1.Items.Add(results2(1))
ListBox1.Items.Add(results3(2))