get a set of strings from a text file based on codes in c# -


i have list of codes inside text file need set of strings starting 1 code one. example, if have following data (there more data in between) need strings between bs001 till ess01

            bs001 customer id|1234|site address||||             ss04,data landmark house, london, united kingdom|||             ess01 || 

currently working read file , go each line. how take substring starting code end of code end of code can in line 5 or 10.

using (streamreader sr = file.opentext(filename))  {      string s = string.empty;       while ((s = sr.readline()) != null)       {            searchstringinaline(s); // method search ess01 in line       }  } 

instead of reading line line, can full file contents string using

sr.readtoend(); 

then build loop , use

int bs001 = s.indexof("bs001"); int es001 = s.indexof("es001"); string finding = s.substring(bs001 + 5, es001 - bs001 - 5); 

plus offsets of prvious findings matching text (including line breaks) between bs001 , es001.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -