Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello.
I have a textfile in this format

title
--------------------------------------------------------
--------------------------------------------------------
itemno | serial no | location | user | name | QTY | Man.
--------------------------------------------------------
1234, 55555, LA, aa12, sam, 5, AEM <<<<<-----start read here
1235
1236


I want to read textfile in above format starting from 6th line,till the end of the line.

Any ideas guys?
Posted

Hi,

you could use File.ReadAllLines for this task. This gives you an array with all the lines in your textfile. You only need to process all the elements starting with the 6th.

JF
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Mar-11 3:15am    
Acceptable, too, a 5 (I still think line reading is better). Also, you will need some effort to split correctly: many use hard-coded line delimiter, which is wrong (non-portable).
See my Answer.
--SA
Espen Harlinn 24-Mar-11 3:37am    
My 5
TweakBird 24-Mar-11 3:57am    
My 5
Are you serious? Do you think somebody needs to think of any ideas?

1) Use the class System.IO.StreamReader.
2) In cycle, use System.IO.StreamReader.ReadLine.
3) Before the loop, create int lineCount = 0;
4) Increment lineCount after each ReadLine.
5) After incrementing lineCount, continue to skip to next line, depending on lineCount.
6) If not skipping line, split the line like this:
string[] terms =
    myLine.Split(
        new char[] {' ', ',', }, 
        System.StringSplitOptions.RemoveEmptyEntries);


Please think about your Question. You should have find it all by yourself and asked a question only if you face a problem. If you're going to keep asking questions like that, you will never complete any development.

—SA
 
Share this answer
 
v2
Comments
Sandeep Mewara 24-Mar-11 3:02am    
My 5!
Sergey Alexandrovich Kryukov 24-Mar-11 3:15am    
Thank you, Sandeep.
--SA
Eduard Keilholz 24-Mar-11 3:15am    
My 5
Sergey Alexandrovich Kryukov 24-Mar-11 3:57am    
Thank you, Eduard.
--SA
Espen Harlinn 24-Mar-11 3:34am    
My 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900