Link to home
Start Free TrialLog in
Avatar of jaimehy
jaimehy

asked on

Reading German special characters using a streamreader with currentEncoding = system.text.utf8encoding

I'm using a streamreader to read a text file.

The streamreader.currentencoding is system.text.utf8encoding

The first line of my test text file is the following string of characters:
Uppercase A with an umlaut (HTML code would be Ä)
Lowercase a with an umlaut (ä)
Uppercase O with an umlaut (Ö)
Lowercase o with an umlaut (ö)
Uppercase U with an umlaut (Ü)
Lowercase u with an umlaut (ü)
The German lowercase "SZ" symbol (ß)

This is interpreted as a series of unknown characters.

What can I do to make the stream reader interpret the text correctly.

Thanks very much in advance,

JaimeHy
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As an alternative to using a FileStream to examine the file, just add a .bin file extension to the file and open it in Visual Studio.
Avatar of jaimehy
jaimehy

ASKER

It gave me the pointers I needed to resolve the problem I had.  More than that I couldn't ask for.
Avatar of jaimehy

ASKER

Thanks for the tips, GreenGhost,

Yes, I did forget to mention that the txt file is encoded in ANSI.  Sorry about that.

The question that I suppose I wanted to ask is how to force the streamreader to read the file as ANSI.  With your help,I've managed to answer it.

The StreamReader.CurrentEncoding property is read only, so no luck there, and I was stuck.   What I eventually did was declare a default encoding and overload the arguments when declaring my streamreader as follows:

        Dim DefaultEncoding As Encoding = Encoding.Default
        Dim sr As New StreamReader(FileToBeRead, DefaultEncoding)

My umlauts now appear perfectly in my output xml file!

Much obliged


JaimeHY