469,625 Members | 1,914 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

ReadLine!!

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
Nov 16 '05 #1
5 2014
Why not read the whole file as one piece into mem and then split it?
Nov 16 '05 #2
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" wrote:
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

Nov 16 '05 #3
Can't do that FileSize > 250MB

"Joep" <St***@DeStoep.nl> wrote in message
news:41***********************@news.xs4all.nl...
Why not read the whole file as one piece into mem and then split it?

Nov 16 '05 #4
Vai2000 <no****@microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
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

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Vai2000 <no****@microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Russell E. Owen | last post: by
reply views Thread by John C. Worsley | last post: by
1 post views Thread by Jian Qiu | last post: by
4 posts views Thread by David Bear | last post: by
3 posts views Thread by PointMan | last post: by
reply views Thread by 7stud | last post: by
6 posts views Thread by Sean Davis | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.