Ive been looking up on google and I cant seem to get anything. I know how to read a text file but I want to just get the second line. How would this be done?
Printable View
Ive been looking up on google and I cant seem to get anything. I know how to read a text file but I want to just get the second line. How would this be done?
You can do loop while reading line by line and stop the loop when you get in the second line
How would I check that its on the second line?
Check out the StreamReader.ReadLine Method. Call it once and do nothing with the results and the 2nd call will get you the 2nd line from the file.
You can't just get a specific line. To get line N you must then you have to read every line before that and, if you don't need them, just discard them.vb.net Code:
Private Function GetLineFromFile(filePath As String, lineNumber As Integer) As String Using reader As New IO.StreamReader(filePath) Dim line As String = Nothing For i = 1 To lineNumber line = reader.ReadLine() If line = Nothing Then 'No more lines Exit For End If Next Return line End Using End Function