parsing - Trying to write a c# program that parses a text file that contains data seperated by headers in square brackets -


im writting program parses specific text file has data in im going prcess later. each part seperated header in square brackets wondering how put each segment array using header name array. below example of begining of text file. ive set form lets choose file want process , ive set way of processing line line using objreader.readline in loop

[params] version=106 monitor=34 smode=111111100 date=20090725 starttime=13:56:44.0 length=00:24:30.5 interval=1 upper1=0 lower1=0 upper2=0 lower2=0 upper3=0 lower3=0 timer1=00:00:00.0 timer2=00:00:00.0 timer3=00:00:00.0 activelimit=0 maxhr=180 resthr=70 startdelay=0 vo2max=51 weight=0  [note] tt warm  [inttimes] 00:24:30.5  140 83  154 174 0   0   0   41  112 33 0   0   0   0   0 0   12080   0   280 0   0 0   0   0   0   0   0  [intnotes]  [extradata]  [summary-123] 1470    0   1470    0   0   0 180 0   0   70 1470    0   1470    0   0   0 180 0   0   70 0   0   0   0   0   0 180 0   0   70 0   1470  [summary-th] 1470    0   1470    0   0   0 180 0   0   70 0   1470  [hrzones] 180 162 144 126 108 90 0 0 0 0 0   

you use pattern this.

list<string> paramslist; list<string> notelist; list<string> templist;  while (line = objreader.readline()) {     if (line.startswith("[")) {          // start new array         if (line.equals("[params]"))             templist = paramslist = new list<string>();         else if (line.equals("[note]"))             templist = notelist = new list<string>();          // etc.      } else if (string.isnullorempty(line)) {          // ignore, end of array      } else {          // add element array         templist.add(line);      } }  // use paramslist, notelist, etc. needed 

i'm not quite sure how mean use header name array. headers same of files? can't dynamically allocate name of variable based on string, nor want if need use in later processing.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -