473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 2128
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Russell E. Owen | last post by:
At one time, mixing for x in file and readline was dangerous. For example: for line in file: # read some lines from a file, then break nextline = readline() # bad would not do what a naive...
0
by: John C. Worsley | last post by:
I've got an extremely inscrutable problem here using Perl's Term::ReadLine::Gnu module. I'm using Perl 5.8.0, readline 4.3 and Term::ReadLine::Gnu 1.14. The problem is specific to catching INT...
1
by: Jian Qiu | last post by:
Hi, I tried to install python2.4.2. Unfortunately building 'readline' extension failed. Here is what I got: (It is a bit long. If you are impatient, please look at the end where it reports the...
4
by: David Bear | last post by:
I built python 2.4.2 for suse linux 9.3. I configured it to be a separate instance of python from the version packaged with suse. Now when I start it I get an error: python Python 2.4.2 (#4,...
3
by: PointMan | last post by:
what i know is... while ((currentStr = sr.ReadLine()) != null) { in this area, can i get next ReadLine Value of currentStr } best regard,,
0
by: 7stud | last post by:
Hi, 1) Does this make any sense: """ Thus, the loop: for line in f: iterates on each line of the file. Due to buffering issues,
6
by: Sean Davis | last post by:
I have a large file that I would like to transform and then feed to a function (psycopg2 copy_from) that expects a file-like object (needs read and readline methods). I have a class like so: ...
0
by: Akira Kitada | last post by:
Hi list, I was trying to build Python 2.6 on FreeBSD 4.11 and found it failed to build some of the modules. """ Failed to find the necessary bits to build these modules: _bsddb ...
0
by: Akira Kitada | last post by:
Hi Marc-Andre, Thanks for the suggestion. I opened a ticket for this issue: http://bugs.python.org/issue4204 Now I understand the state of the multiprocessing module, but it's too bad to see...
0
by: M.-A. Lemburg | last post by:
On 2008-10-25 20:19, Akira Kitada wrote: Thanks. The errors you are getting appear to be related to either some missing header files or a missing symbol definition to enable these - looking...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.