vb.net - Reading last five lines of a csv file -
I am using the following code to read the first 1000 lines - only the first 6 columns - from CSV and them Keep Array P2 (,):
fName = "c: \ temp \ filexx.csv" If System.IO.File.Exists (fName) = true then StreamReader as a tmpstream = File Split (Environment.NewLine): SplitLine = Split (TextLine (0), ",") For X = 0 to 999 only read first 1000 rows Strline = Textline (X) Y = 0 to 5 '6 columns Next 2 for P2 (X, Y) = Strline (Y) Ampstrymkclos () Alse Msbibiboks ( "file does not exist") End If But I am interested in the last 5 lines. Therefore, I should change
TextLine = tmpstream.ReadToEnd (). Split (Environment.NewLine) TextLine = tmpstream.ReadLine (fName.Length - 6) But I do not know how to do it. Thank you very much for your hints, your links, your patience and your clarity.
The only way to read is to use CSV The last 6 rows of all the lines have to be read, and you keep track of the last 6 while reading.
Since the CSV format allows each row to have variable width, there is no way
You are currently reading in the entire file, which contains an array containing all the rows < Creating code> TextLine
TextLine = tmpstream.ReadToEnd (). Split (Environment.NewLine) To get your answer, just access the last 6 elements of TextLine .
Comments
Post a Comment