472,145 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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 2078
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.