How can I ignore a blank line in a text file using VB.NET?

How can I ignore a blank line in between the data in a text file using VB.NET?

For example, I have a file with data like this

Line 1: 020220date20101231salesvalue52..
Line 2: 356465date20101231salesvalue52..
Line 3: Blank Line 
Line 4: **strong text**
Line 5: 356465date20101231salesvalue52..
Line 6: 356465date20101231salesvalue52..
Line 7: Blank Line
Line 8: 356465date20101231salesvalue52..
Line 9: 356465date20101231salesvalue52..
continues...

Upvotes: 0

Views: 5239

Answers (3)

Tilak
Tilak

Reputation: 30688

LINQ way (if file is not big enough)

  File.ReadAllLines("textFile.txt").Where(i=> !String.IsNullOrEmpty(i))

Upvotes: 1

Yorrick
Yorrick

Reputation: 377

As I have just learned about the

Dim reader As New IO.StreamReader("filepath")

method, I'ld say use that.

Then you could have a code looking like this(-ish)

        line = reader.ReadLine()
        if line <> ""
            list.Add(line)
        end if

Upvotes: 0

Jonathan Wood
Jonathan Wood

Reputation: 67175

You can open a stream and use ReadLine(). Then, just check if the current line is empty and, if so, skip to the next one.

Upvotes: 0

Related Questions