Search code examples
c#iofile-read

Skip data when reading a text file


i have a text file ... which storing data like..

E:0

S:0

R:0

G:0

E:1

S:1

R:1

G:1

and so on till 50. I can read it by

StramReader.ReadLine();

but how i can read the 1st line

E:0

and skip to the next E: , without getting the in between things


Solution

  • There is this way. But this will go through each row and select the rows that contains E

    var linesContainsE = File.ReadAllLines(filename)
        .Where(line => line.Contains("E"))
        .ToList();
    

    (Using namespace System.Linq and System.IO)

    More info about the File.ReadAllLines from msdn : http://msdn.microsoft.com/en-us/library/system.io.file.readalllines.aspx