0

我在 Visual Basic .net 中有这个结构

Private Structure queueT
        Public name As String
        Public parent As String
        Public limitat As Integer
        Public maxlimit As Integer

这是我得到的数据,我将其存储在一个一维字符串数组中(仅粘贴 3):

!re=.id=*10000B0=name=Up-PBX=parent=Up=packet-mark=pack_pbx=limit-at=256000=queue=PCQ_Up=priority=1=max-limit=512000=burst-limit=0=burst-threshold=0=burst-time=00:00:00=invalid=true=disabled=true=comment=PBX

!re=.id=*10000C7=name=Down_Mauro=parent=Down=packet-mark==limit-at=315000=priority=8=max-limit=5000000=burst-limit=0=burst-threshold=0=burst-time=00:00:00=invalid=false=disabled=true

!re=.id=*10000C8=name=Down_Mauro_dom=parent=Down_Mauro=packet-mark=pack_Mauro_dom=limit-at=40000=queue=PCQ_Down=priority=2=max-limit=400000=burst-limit=0=burst-threshold=0=burst-time=00:00:00=invalid=false=disabled=true

我需要将信息存储在我的结构中,所以它看起来像这样:

queueT.name = UP-PBX
queueT.parent = UP
queueT.limitat = 256000
queueT.maxlimit = 512000

我只需要上面提到的信息,不需要其他的。我怎样才能做到这一点?

谢谢!!

4

1 回答 1

2

看起来它是第一个值之后的键/值对。从您的样本中,这样的东西可能会起作用。

Private Function queueTParse(item As String) As queueT

    Dim queueValues = item.Split("=")
    Dim queueTItem = New queueT

    For i As Integer = 1 To queueValues.Length - 1 Step 2

        Select Case queueValues(i)
            Case "name"
                queueTItem.name = queueValues(i + 1)
            Case "parent"
                queueTItem.parent = queueValues(i + 1)
            Case "limit-at"
                queueTItem.limitat = queueValues(i + 1)
            Case "max-limit"
                queueTItem.maxlimit = queueValues(i + 1)
        End Select

    Next

    Return queueTItem

End Function
于 2013-04-04T16:03:11.153 回答