我有一个字符串:
Membership information ---------------------- Nodeid Votes Name 2 1 MXQSRV2 1 1 pve (local)
我需要的数据是:
2 1 MXQSRV2 1 1 pve (local)
这转换为:
Nodeid(Needed) Votes(Can be thrown away) Name(Needed) Nodeid(Needed) Votes(Can be thrown away) Name(Needed)
我想要的结果是一个列表框,显示:
1 pve
2 MXQSRV2
这意味着:NodeID名称
但如果该列表更长可以适应
我需要在Name前面的两个数字中的第一个,第二个数字可以被丢弃,然后是Name。 我到目前为止的守则是:
Dim phaze2 As String = Replace(input, " (local)", "")
Dim phaze3 As String = Replace(phaze2, "Membership information", "")
Dim phaze4 As String = Replace(phaze3, "----------------------", "")
Dim phaze5 As String = Replace(phaze4, "Node", "")
Dim phaze6 As String = Replace(phaze5, "id", "")
Dim phaze7 As String = Replace(phaze6, "Votes", "")
Dim phaze8 As String = Replace(phaze7, "Name", "")
Dim phaze9 As String = Replace(phaze8, " ", "")
然后返回:
*return*
*return*
*return*
*return*
21 MXQSRV2
11 pve
*return*
思想?
答案 0 :(得分:1)
因为你的字符串数据是一致的,你可以删除额外的填充,然后拆分字符串,如下所示:
While data.Contains(" ")
data = data.replace(" ", " ")
End While
Dim values() as string = data.split(" ")
完成此操作后,您可以使用字段的索引并连接值来根据需要获取值。例如:
Label1.Text = values(3) & " " & values(7)