StreamReader, reading specific line in txt file

Conqu3st

New member
Joined
Apr 3, 2007
Messages
4
Programming Experience
Beginner
After hours of looking I've decided to seek help =/
(I use MVS 2002, for what its worth)

Just looking for basic code, heres an example situation:
....
strLine2 = StreamReader reading line 2 from "/mytext.txt"


thanks for any help, sorry if its not clear what im trying to do ;(
con
 
You can use the readline property of your streamreader.
Simply count the lines read, if it's 2, fill your string.
Just as in the following example:

Dim myStreamReader As System.IO.StreamReader
Dim iRowCounter As Integer = 0
Dim sReadLine As String
Dim strLine2 As String
Dim sFileName As String = "[The location and name of the file]"
myStreamReader = File.OpenText(sFileName)
Do While Not myStreamReader.EndOfStream()
iRowCounter += 1
sReadLine = myStreamReader.ReadLine()
If iRowCounter = 2 Then
strLine2 = sReadLine
End If
Loop
 
Last edited:
Back
Top