1

我需要将 .csv 文件读入数组,但我不希望 .csv 文件的第一行位于数组中。我该如何排除它?

'Create array.
        Dim sReader As New StringReader(strBuffer)
        Dim List As New List(Of String)
    Do While sReader.Peek >= 0
        List.Add(sReader.ReadLine)
    Loop
        Dim lines As String() = List.ToArray
        sReader.Close()
4

2 回答 2

2

你能删除列表中的第一个元素吗?

List.RemoveAt(0);

于 2013-07-26T18:15:14.427 回答
1

您还可以在循环之前执行 readline:

'Create array.
        Dim sReader As New StringReader(strBuffer)
        Dim List As New List(Of String)
        sReader.ReadLine
    Do While sReader.Peek >= 0
        List.Add(sReader.ReadLine)
    Loop
        Dim lines As String() = List.ToArray
        sReader.Close()

你可以通过使用来简化你的代码

Dim lines As String() = File.ReadAllines("MycsvFile.csv")
lines.RemoveAt(0)
于 2013-07-26T19:33:25.540 回答