2

I have a question regarding the reading sequence of an array which is converted from a text log file.

As there are file headers that I do not need to be read during a process located in the first lines[0] are there any methods to skip reading lines[0] and start reading lines[1] first?

The program utilizes a foreach loop to read through the array. And there is a tokenizing method therefore the foreach loop is required for the tokenizing to recorgnize the String format of the array.

Please do help by advising on the codes! Thanks!

The program codes:

class Program
{
    static void Main(string[] args)
    {
        System.Collections.Generic.IEnumerable<String> lines = File.ReadLines("C:\\syscrawl\\ntfs3.txt");

        foreach (String r in lines) //Start reading from lines[1] first instead?
        {
            String[] token = r.Split(',');
        }
    }
}

In case you need the log text file here's an example:

Date,Size,Type,Mode,UID,GID,Meta,File Name // Lines[0]
Sun Jul 22 2001 02:37:46,73882,...b,r/rrwxrwxrwx,0,0,516-128-3,C:/WINDOWS/Help/digiras.chm // Lines [1]
Sun Jul 22 2001 02:44:18,10483,...b,r/rrwxrwxrwx,0,0,480-128-3,C:/WINDOWS/Help/cyycoins.chm
Sun Jul 22 2001 02:45:32,10743,...b,r/rrwxrwxrwx,0,0,482-128-3,C:/WINDOWS/Help/cyzcoins.chm
Sun Jul 22 2001 04:26:14,174020,...b,r/rrwxrwxrwx,0,0,798-128-3,C:/WINDOWS/system32/spool/drivers/color/kodak_dc.icm

2 Answers 2

6

Use the Skip extension method. E.g.

foreach (String r in lines.Skip(1)) //Start reading from lines[1] first instead
{
   String[] token = r.Split(',');
}

If you want to examine the lines instead of relying on the count, you could use SkipWhile. E.g.

foreach (String r in lines.SkipWhile(l => l.StartsWith(HeaderInfo)) 
{
   String[] token = r.Split(',');
}
Sign up to request clarification or add additional context in comments.

Comments

3

Use .Skip:

foreach (String r in lines.Skip(1))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.