c# - Find all lines that contains given string -


system.io.streamreader file = new system.io.streamreader(@"data.txt"); list<string> spec= new list<string>(); while (file.endofstream != true) {     string s = file.readline();     match m = regex.match(s, "spec\\s");     if (m.success)     {         int = convert.toint16(s.length);         = - 5;         string part = s.substring(5, a);         spec.add(part);      } } 

i'm trying lines contains word "spec" , space character error when run program.

the details of exception follows:

an unhandled exception of type 'system.argumentoutofrangeexception' occurred in mscorlib.dll

could assist me on figuring out why?

text file:

id  560 spec    ... bla bla   blah... blah... bla bla  bla category    other price   $259.95    id  561 spec    more blah blah...  blah... blah... bla bla  bla category    other price   $229.95 

system.io.streamreader file = new system.io.streamreader("data.txt"); list<string> spec = new list<string>(); while (!file.endofstream) {     if(file.readline().contains("spec"))      {         spec.add(s.substring(5, s.length - 5));     } } 

that might work.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -