c# - Read multiple lines with StreamReader with StreamReader.Peek -


let's have following file format (key value pairs):

objec1tkey: object1value object2key: object2value object3key: object3value object4key: object4value1 object4value2 object4value3 object5key: object5value object6key: object6value 

i'm reading line line streamreader. objects 1, 2, 3, 5 , 6 wouldn't problem because whole object on 1 line, it's possible process object.

but object 4 need process multiple lines. can use peek this? (msdn peek: returns next available character not consume it.). there method peek returns next line , not character?

if can use peek, question is, can use peek 2 times can read 2 next lines (or 3) until know there new object (obect 5) processed?

i recommend separate io line handling entirely.

instead of making processing code use streamreader, pass either ilist<string> or ienumerable<string>... if use ilist<string> make easy access lines index (so can keep track of "the key i'm processing started @ line 5" or whatever), mean either doing clever or reading whole file in 1 go.

if it's not big file, using file.readalllines going simplest way of reading file list of lines.

if is big file, use file.readlines obtain ienumerable<string>, , processing code needs bit smarter... example, might want create list<string> each key processes, containing lines key - , let list garbage collected when read next key.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -