将项目在列表框中分配到并行列表中



对于显示列表框中的每一行,我需要将行分解为子字符串:年份和温度,将它们转换并将其值插入并行列表中。我非常沮丧,因为我确定它很简单,但是我整夜都在从事这个项目。

我正在使用的列表框数据是我导入的CSV文件,并包含看起来像

的数据

1999,6.654616
2000,8.616851
2001,6.61681

这是我当前的代码。

'Open File Dialog
        Dim dlg As New OpenFileDialog With {
            .Filter = "CSV Files|*.csv|Text Files|*.txt|All Files|*.*",
            .Title = "Please select CSV Data",
            .InitialDirectory = "C:"
        }
        dlg.ShowDialog()
        'Declaring streamreader object
        R = New IO.StreamReader(dlg.FileName)
        While (R.Peek() > -1)
            ListBoxDisplay.Items.Add(R.ReadLine)
        End While
        R.Close()
        'Testing
        'List
        Dim year As New List(Of Integer)
        Dim avgtemp As New List(Of Double)

string.split应该为您工作。

Private Sub GetLists()
        Dim year As New List(Of Integer)
        Dim avgtemp As New List(Of Double)
        While (R.Peek() > -1))
            Dim line As String = R.ReadLine
            ListBoxDisplay.Items.Add(line)
            Dim strArray() As String = line.Split(","c)
            year.Add(CInt(strArray(0)))
            avgtemp.Add(CDbl(strArray(1).Trim))
        End While
        R.Close()
End Sub

最新更新