字符串比较不适用于字符串数组

时间:2015-04-10 12:37:30

标签: vb.net

启动cfg文件,这是文件:

http://pastebin.com/mE3Y3wiq

我正在做的是寻找一个类,一旦找到我将THAT类的数据存储在列表框中,所以例如:如果我正在寻找“修复”,我会将每行存储在后面的列表框中“{Fixing}”直到我们点击下一个类或文件结尾(对于修复我们将停在“{Pillars}”)

这是我的代码:

Private Sub tvList_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles tvList.AfterSelect
        Dim cfgData() As String
        ' Dim lstData As New ListBox()

        lstData.Items.Clear()

        If rbnInch.Checked Then
            cfgData = File.ReadAllLines("C:\Library\Common\PARAM-NG\Dbs\Mould\Dme_I\Dme_I.cfg")
        Else
            cfgData = File.ReadAllLines("C:\Library\Common\PARAM-NG\Dbs\Mould\Dme\Dme.cfg")
        End If

        Dim classID As Short = tvList.SelectedNode.Index
        Dim classType As String = tvList.Nodes.Item(classID).Text

        Try
        For i As Short = 0 To cfgData.Count - 1
            If cfgData(i).Contains("{" & classType & "}") Or cfgData(i).Contains("{" & classType.Replace(" ", "") & "}") Then
                i += 1
                Do
                    lstData.Items.Add(cfgData(i))
                    i += 1
                    If cfgData(i).Contains(tvList.Nodes.Item(tvList.SelectedNode.Index + 1).Text.Replace(" ", "")) Or cfgData(i).Contains(tvList.Nodes.Item(tvList.SelectedNode.Index + 1).Text) Or cfgData(i).ToString() Is vbNullString Then
                        Exit Do
                    End If
                Loop
            End If
        Next
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

    End Sub

现在我只获得了我的列表框中的第一行,就是这样。需要帮助收集我需要的数据然后停在下一个类或文件的末尾(最后一个类的文件结束,因为它之后没有可以标记我退出的类)

1 个答案:

答案 0 :(得分:2)

已提取from the question并代表OP发布。


我自己解决了。

Private Sub tvList_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles tvList.AfterSelect
    Dim cfgData() As String
    ' Dim lstData As New ListBox()

    lstData.Items.Clear()

    If rbnInch.Checked Then
        cfgData = File.ReadAllLines("C:\Library\Common\PARAM-NG\Dbs\Mould\Dme_I\Dme_I.cfg")
    Else
        cfgData = File.ReadAllLines("C:\Library\Common\PARAM-NG\Dbs\Mould\Dme\Dme.cfg")
    End If

    Dim classID As Short = tvList.SelectedNode.Index
    Dim classType As String = tvList.Nodes.Item(classID).Text

    Try
        For i As Short = 0 To cfgData.Count - 1
            If cfgData(i).Contains("{" & classType) Or cfgData(i).Contains("{" & classType.Replace(" ", "")) Then
                i += 1
                Do
                    If tvList.SelectedNode.Index + 1 >= tvList.Nodes.Count Then
                        If i >= cfgData.Count - 1 Then
                            lstData.Items.Add(cfgData(i))
                            Exit Do
                        ElseIf cfgData(i) = vbNullString Then
                            lstData.Items.Add(cfgData(i))
                            i += 1
                        ElseIf cfgData(i).Substring(0, 1).Contains("{") Then
                            Exit Do
                        Else
                            lstData.Items.Add(cfgData(i))
                            i += 1
                        End If
                    ElseIf i >= cfgData.Count - 1 Then
                        lstData.Items.Add(cfgData(i))
                        Exit Do
                    ElseIf cfgData(i) = vbNullString Then
                        lstData.Items.Add(cfgData(i))
                        i += 1
                    ElseIf cfgData(i).Substring(0, 1).Contains("{") Then
                        Exit Do
                    Else
                        lstData.Items.Add(cfgData(i))
                        i += 1
                    End If
                Loop
            End If
        Next
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub