在VB.Net中解析帮助

时间:2014-11-20 22:00:19

标签: vb.net parsing

我不确定如何说出这个问题,也不知道怎么做,所以我想我会来这里寻求一些见解。那么,什么是运行命令并获取返回数据的查询程序,这些数据返回到这样。

[0]: 
    ServerId: 1
    ServerPort: 9987
    ServerStatus: Online
[1]: 
    ServerId: 13
    ServerPort: 4000
    ServerStatus: Online
[2]: 
    ServerId: 14
    ServerPort: 4001
    ServerStatus: Online
[3]: 
    ServerId: 15
    ServerPort: 4002
    ServerStatus: Online
[4]: 
    ServerId: 16
    ServerPort: 4003
    ServerStatus: Online
[5]: 
    ServerId: 17
    ServerPort: 4004
    ServerStatus: Online
[6]: 
    ServerId: 18
    ServerPort: 4005
    ServerStatus: Online
[7]: 
    ServerId: 19
    ServerPort: 42069
    ServerStatus: Online
[8]: 
    ServerId: 20
    ServerPort: 4006
    ServerStatus: Online
[9]: 
    ServerId: 21
    ServerPort: 5022
    ServerStatus: Online
[10]: 
    ServerId: 23
    ServerPort: 4007
    ServerStatus: Online
[11]: 
    ServerId: 24
    ServerPort: 4008
    ServerStatus: None
[12]: 
    ServerId: 25
    ServerPort: 4009
    ServerStatus: Online
[13]: 
    ServerId: 26
    ServerPort: 4010
    ServerStatus: Online
[14]: 
    ServerId: 27
    ServerPort: 4011
    ServerStatus: Online
[15]: 
    ServerId: 28
    ServerPort: 4012
    ServerStatus: Online

现在不仅有15台服务器可以更改,而且可以达到任何数量。我怎样才能从每个小数据中提取数据,哦,你会怎么说,信息片段?按照从最小到最大的顺序排列到列表框中,从0开始到之后。有任何想法吗?提前谢谢!

[0]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 56
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10000
    ServerUptime: 18.05:22:01
    ServerName: The FourHorsemens & The Disciples
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 1
    ServerPort: 9987
    ServerStatus: Online
[1]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 18.15:03:24
    ServerName: NotYoda
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 13
    ServerPort: 4000
    ServerStatus: Online
[2]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 18.15:03:24
    ServerName: CYNTEX HF - TS3 Server :D
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 14
    ServerPort: 4001
    ServerStatus: Online
[3]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 18.15:03:24
    ServerName: GuyCheap
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 15
    ServerPort: 4002
    ServerStatus: Online
[4]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 18.15:03:24
    ServerName: Game All Day
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 16
    ServerPort: 4003
    ServerStatus: Online
[5]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 18.15:03:24
    ServerName: #Cloud9
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 17
    ServerPort: 4004
    ServerStatus: Online
[6]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 50
    ServerUptime: 18.15:03:24
    ServerName: FuryTech
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 18
    ServerPort: 4005
    ServerStatus: Online
[7]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 3
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 100
    ServerUptime: 11.18:18:51
    ServerName: Frost-Hosting - A Teamspeak Hosting Service
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 19
    ServerPort: 42069
    ServerStatus: Online
[8]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 18.15:03:24
    ServerName: Hangout
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 20
    ServerPort: 4006
    ServerStatus: Online
[9]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 18.14:56:17
    ServerName: stevenwitha4.6@gmail.com's_Teamspeak_Server!
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 21
    ServerPort: 5022
    ServerStatus: Online
[10]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 17.20:32:39
    ServerName: Straight Flush Gaming
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 23
    ServerPort: 4007
    ServerStatus: Online
[11]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 
    ServerNumberOfQueryClientsOnline: 
    ServerMaximumClientsAllowed: 
    ServerUptime: 
    ServerName: 1r6ddyce@gmail.com
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 24
    ServerPort: 4008
    ServerStatus: None
[12]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 1
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 13.01:01:34
    ServerName: Welcome to Gaming Room - by Anders & Christian
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 25
    ServerPort: 4009
    ServerStatus: Online
[13]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 3
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 12.21:46:55
    ServerName: Reineling's teamspeak
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 26
    ServerPort: 4010
    ServerStatus: Online
[14]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 12.00:04:56
    ServerName: CrashGFX
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 27
    ServerPort: 4011
    ServerStatus: Online
[15]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 10
    ServerUptime: 12.00:03:52
    ServerName: XBL Hammer
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 28
    ServerPort: 4012
    ServerStatus: Online
[16]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 50
    ServerUptime: 7.18:43:07
    ServerName: Team Battles!
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 29
    ServerPort: 10000
    ServerStatus: Online
[17]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 100
    ServerUptime: 6.19:17:32
    ServerName: YoloMcSwagins
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 30
    ServerPort: 4013
    ServerStatus: Online
[18]: 
    UniqueId: 
    ServerNumberOfClientsOnline: 0
    ServerNumberOfQueryClientsOnline: 0
    ServerMaximumClientsAllowed: 20
    ServerUptime: 6.19:16:30
    ServerName: -Cybia-
    ServerAutoStart: True
    ServerMachineId: 
    ServerId: 31
    ServerPort: 4014
    ServerStatus: Online

1 个答案:

答案 0 :(得分:1)

所以你可以制作这样的函数:

Private Shared Function GetResults(match As String) As Dictionary(Of [String], [String])
    Dim num = Regex.Match(match, "\[(\d+)\]").Groups(0).Value 'Gets the ID of the entry
    Dim allIds = Regex.Matches(match, "(\w+): (.+)") 'Gets each key/value
    Dim dictionary = New Dictionary(Of [String], [String])()

    dictionary.Add("Index", num)
    For Each i As Match In allIds
        dictionary.Add(i.Groups(1).Value, i.Groups(2).Value)
    Next
    Return dictionary
End Function

然后可能这样称呼它:

Dim reg = Regex.Matches(yourValue, "\[\d*\]:(\s+\w+:.+){1,}") 'yourValue is all of the servers
Dim allEntries = (From i As Match In reg Select GetResults(i.Value)).ToList()