StreamReader dropping characters

  • Thread starter Thread starter nobody
  • Start date Start date
N

nobody

I'm using a StreamReader object like this to read a text file.

Dim sr As New IO.StreamReader(Filename)
Dim Line As String = sr.ReadLine()
Do While (Not Line Is Nothing)
ProcessLine(Line)
Loop
sr.Close()

It's been working fine (or so I thought) for weeks. I just noticed that it
was dropping some characters from the stream. Any accented characters are
being dropped. "Toms Spezialitäten" gets read as "Toms Spezialitten" (the
"ä" gets dropped). This is bad because it changes the data being read, but
it's even worse because the lines I'm reading are fixed-width fields and
dropping characters shifts all the data in subsequent fields and really
screws the data up.

Is this a normal (documented) behavior of StreamReader, and what should I
use instead of StreamReader? I can read the file manually, I was just using
StreamReader for it's built-in ability to parse "lines" (cr, lf, or cr/lf
delimited). But I would think as rich as the .NET framework is, there must
be some other kind of stream reader I can use.

-----
 
I solved my own problem. I had to do:

Dim sr As New IO.StreamReader(Filename, System.Text.Encoding.Default)
 
Back
Top