Re: StreamReader ReadLine alternate End Of Line

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




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).

.



Relevant Pages

  • ANNOUNCE: Text-CSV_XS 0.28
    ... Added t/45_eol.t, eol tests ... surrounding the separation character is removed when parsing. ... even though it violates the CSV specs. ...
    (comp.lang.perl.modules)
  • Re: Mixed text/binary data handling
    ... > Is it possible to tell to MatLab's FGETL function to use only one EOL ... Shouldn't be fgetlthat needs told...it's fopenw/ the 't' option that controls the correct newline character interpretation for the platform. ... But, if you have somehow managed to actually create a hybrid file, you may have to either parse it all directly or open it first as text then close it and reopen as binary and then fseekpast that for the stream data portion. ... under windows different programs behave differently: notepad uses CR+LF while wordpad uses just LF as EOL cherecter. ...
    (comp.soft-sys.matlab)
  • Re: A issue on different types of end-of-line / EOL character in the tex file.
    ... It's well known that the different Operating systems use different ... I have a question that if I firstly edit a tex file on ... TeX understands the native EOL symbol for the platform it runs on. ... character it gets, and substitutes it with the EOL character of the ...
    (comp.text.tex)
  • Re: A issue on different types of end-of-line / EOL character in the tex file.
    ... It's well known that the different Operating systems use different ... I have a question that if I firstly edit a tex file on ... TeX understands the native EOL symbol for the platform it runs on. ... character it gets, and substitutes it with the EOL character of the ...
    (comp.text.tex)