djcskinner

djcskinner

  • NA
  • 15
  • 0

text file io

Mar 14 2005 4:39 PM
sorry for posting such an easy question, but i am young and very much learning! i have a text file which i wish to read from, but i only want to read certain blocks of it at a time. the number of lines in each block will vary, depending on certain values being present at the start of lines, so i cant just say something like read lines 1-10 for example, as the lines i want to analyse in the first block may be the first ten lines in one file, and then for example the first 23 lines in another file. i am then trying to perfrom different tasks depending on the contents of these lines, eg if there is a certain value present in a line beginning with for example XP3, i will draw a red line, or a blue line etc. my question is how do i step through text files doing this? i have become confused trying to do this and i cant find anything useful on the web as most file io in c# only covers reading a whole file at once, and not line by line or by depending on what they start with. when i use ReadLine i find myself restricted to the first line of the text file... so is there a way to position the "cursor" at any line in a file, and to read in a block of lines until it gets to a certain line later on, then to use the data within these lines to perfrom other tasks depending on what is found in the file in these lines (even if it is as trivial as just assigining the data to a string value for example)? apologies if this is too easy for this forum, but i am just beginning and need some help! even links to appropriate websites would be very much appreciated.

Answers (9)