我需要将.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()
您能删除列表中的第一个元素吗?
List.RemoveAt(0);
您也可以在循环之前执行一行读取:
'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)