Re: StreamReader ReadLine alternate End Of Line
- From: Samuel R. Neff <samuelneff@xxxxxxxxxx>
- Date: Fri, 08 Dec 2006 17:22:22 -0500
StreamReader.ReadLine didn't changed between 1.1 and 2.0, they both
have the same logic:
read up to the first \r or \n. That's EOL. If the EOL was an \r and
the next character is \n, then discard the \n. So the end result is
that \r, \n, or \r\n is treated as EOL and that's not configurable.
You're correct about the internal state variables--I completely forgot
about them. However base.ReadLine does not have to be called and
shouldn't be called in order to preserve the \r and \n characters.
Simply call base.Read() in a loop until you hit \r\n and preserve \r
in the output string.
Best regards,
Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Fri, 8 Dec 2006 16:57:02 -0500, "Dave Sexton"
<dave@jwa[remove.this]online.com> wrote:
Hi Samuel,
It seems that you are correct for the 2.0 framework; however, based on what
the OP stated:
"The end of line marker is X'0D' X'0A' or "\r\n". My first ReadLine picks up
the characters of the string up to the first X'0D'. The second ReadLine
picks
up the rest of the line."
(0xD 0xA is \r\n)
I assume that the 1.* framework is being used (MSDN doesn't state that "\r"
is one of the hard-coded characters in earlier framework versions).
Anyway, if I'm wrong and the OP is using 1.*, the problem with ripping the
code from base.ReadLine is that it gets and sets internal state and uses an
internal buffer, which simply doesn't make sense to have to rewrite (using
reflection). In other words, base.ReadLine must be called.
The OP might want to try using a Regex, but I'm not sure if it will perform
as well as a simple, custom reader that just scans each character once. A
custom implementation shouldn't derive from StreamReader and shouldn't be
difficult to write either (just use a StreamReader internally to consume
each character one at a time).
.
- Follow-Ups:
- Re: StreamReader ReadLine alternate End Of Line
- From: Dave Sexton
- Re: StreamReader ReadLine alternate End Of Line
- References:
- Re: StreamReader ReadLine alternate End Of Line
- From: Samuel R . Neff
- Re: StreamReader ReadLine alternate End Of Line
- From: Dave Sexton
- Re: StreamReader ReadLine alternate End Of Line
- From: Samuel R . Neff
- Re: StreamReader ReadLine alternate End Of Line
- From: Dave Sexton
- Re: StreamReader ReadLine alternate End Of Line
- Prev by Date: Re: BindingList<> notification before delete?
- Next by Date: Move from VB.NET to C#
- Previous by thread: Re: StreamReader ReadLine alternate End Of Line
- Next by thread: Re: StreamReader ReadLine alternate End Of Line
- Index(es):
Relevant Pages
|