ReadLine!!

  • Thread starter Thread starter Vai2000
  • Start date Start date
V

Vai2000

Hi All, back in VC++ we had flexibility of reading the line defined by our
own terminator...
get(buf,sizeof(buf),chTerminator);

Is there something similar in C#... My file is not terminated by new
lines...instead they are terminated by a special character..I want to avoid
doing a read byte by byte to the terminator, instead want to read the whole
line at once...but use the terminator of my choice instead of \n or \r\n


TIA
 
Why not use read to end and then split
ie
StreamReader istream = new StreamReader(filename);
string[] lines = istream.ReadToEnd().Split('c');

where 'c' is your delimiter, you then have an array of lines, which you can
process.
 
Vai2000 said:
Hi All, back in VC++ we had flexibility of reading the line defined by our
own terminator...
get(buf,sizeof(buf),chTerminator);

Is there something similar in C#... My file is not terminated by new
lines...instead they are terminated by a special character..I want to avoid
doing a read byte by byte to the terminator, instead want to read the whole
line at once...but use the terminator of my choice instead of \n or \r\n

Don't read a byte at a time, but read chunks at a time, still using
StreamReader, but reading (say) 8192 characters at a time. If you don't
find your delimiter, append it to a StringBuilder. If you do, process
that chunk.
 
Thanks u all, I guess my question was addressing a different point. I know
how to do the suggestions.

If u guys know the specific answer..please feel free.

TIA
 
Back
Top