如何读取除.CSV文件的标题行之外的所有内容?

时间:2013-07-26 18:11:31

标签: arrays vb.net csv stringreader

我需要将.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()

2 个答案:

答案 0 :(得分:2)

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

List.RemoveAt(0);

答案 1 :(得分: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)