How to omit the first line when reading from a text file?

wonder_gal

Active member
Joined
Jun 5, 2006
Messages
34
Programming Experience
1-3
Hi,

I am writing a function to read from a text file.
May I know is there any vb.net built in function that I can use to omit the first line while reading the text file.

My current code is

VB.NET:
[COLOR=black]Dim oReader As New System.IO.StreamReader(strFilePath)

[COLOR=Red]XXXXXXXXXXXXXXXXXXXXXXXXXX[/COLOR]
[/COLOR]strTextLine = oReader.ReadToEnd
oReader.Close()
Is there any condition that I can check so that I can avoid reading the first line? Thanks.
 
Not with ReadToEnd method, but you can use the ReadLine method to read all lines and ignore the first. Or String.Split the full file string by newlines to a "lines" array. For the latter case you can also use a textbox if you're not up to splitting the text yourself, just assign the readalltext return string to the textbox.text property and use the textbox.lines array.
 
Ok, I'll use the ReadLine method then. But my question here is that is there any method/ function that can allow me to skip reading the first line?
 
VB.NET:
Dim Str As New System.Text.StringBuilder
Dim oReader As New System.IO.StreamReader(strFilePath)
oReader.ReadLine 'This skips the first line
Do While oReader.Peek <> -1
    Str.Append(oReader.ReadLine & Environment.NewLine)
Loop
oReader.Close()
strTextLine = Str.ToString
 
Hi JuggaloBrotha,

Ya, by placing this line

VB.NET:
oReader.ReadLine
ahead of

VB.NET:
Do While oReader.Peek <> -1
    Str.Append(oReader.ReadLine & Environment.NewLine)
Loop
really does the magic of skipping first line!

Thanks for sharing. :)
 
Last edited:
Back
Top