simple textfile reader - doesnt support extended ASCII?

  • Thread starter Thread starter Jacco
  • Start date Start date
J

Jacco

Hi,

I have this simple textfile I want to read from disk. It works fine, only
characters like ö ÿ and ü are skiped during the import.
I open a streamreader like this:

sr = System.IO.File.OpenText(QUESTIONS_FILENAME)

And read each line like this:

SingleLine = sr.readline()

Any hints, tips or workarounds how to solve this?

Any help is greatly appreciated!

thx! Jacco
 
you might have to set the encoding
new StreamReader(new FileStrean(aFile), Encoding.UTF8);
 
Hi Lloyd,

I forgot to mention; I'm working in VB.net for compact framework.

The streamreader has no overloads which accepts a second parameter. So
unfortunately your solutions doesn't work for me (or maybe I am overlooking
something?)

Jacco
 
Jacco it's puzzling.

Personally I don't know VB.NET, however I do program for the compact
framework (in C#) and StreamReader do have a constructor with a second
encoding parameter.
I find it strange you don't have the same in VB .....

maybe a problem with intellisense/code completion, as I know sometime and
for some reason (probably a bug) VS.NET behave strangely and completly miss
a few existing method.

so go and look at the .NET documentation

the StreamReader has a constructor:
Public Sub New(
ByVal stream As Stream
ByVal encoding As Encoding
); // (straight from .NET doc)

which is supported by the Compact Framework / Windows CE / PPC (as claim at
the bottom of the page and used by me a few times)
 
Just a restart of the .net design environment did the trick. ;)

The completed code:
Dim fs As FileStream = File.OpenRead(QUESTIONS_FILENAME)

Dim sr As StreamReader = New StreamReader(fs, System.Text.Encoding.Default)

thx again!
Jacco
 
Back
Top