Reputation: 469
Is there a way to read ahead to the next line of a csv fine while still being on the current line? I need to insert some info into a database but I need a value from the line ahead...
Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser("D:\TEMP\HB\" & fName.ToString)
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
currentRow = MyReader.ReadFields()
nextRow = ?????
End While
Upvotes: 1
Views: 596
Reputation: 101
I don't know of any such function in the TextFieldParser
class.
Anyway remember that as soon as you ReadFields()
into currentRow
, the file cursor is moved to the next line so when your code reach nextRow = ?????
instruction the file cursor is already on that row. If you need to read the content of that row without "consuming" it, you can use the PeekChars(n)
function wich will read "n" chars from the current line without moving the cursors position, leaving the line still usable from a following ReadFields()
call.
Upvotes: 2