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