streamreader won't read some characters

Levu

Well-known member
Joined
Jun 13, 2007
Messages
51
Location
Norway - Drammen
Programming Experience
1-3
I got a problem with my streamreader.
It won't read the norwegian characters: øæå..

iv tried to change like this:

VB.NET:
            objReader = New System.IO.StreamReader(path, System.Text.Encoding.ASCII)
But that won't work either..

Anyone know how to get it to work?

Edit: I'v checked the textfile in HEX editor..
æ = E6 it says.. If thats of any help..
Notepad reads it, so it should be possible.. Atleast i hope so :p
 
Last edited:
ASCII encoding doesn't support extended characters, try one of the UTF ones or System.Text.Encoding.Default.
 
1252 is also the default codepage for western european Windows systems. According to Wiki "UTF-8 is recommended instead of windows-1252 for modern applications", I'm not sure how good that statement is, but I know that 1252 is referred to as ANSI (ASCII) derived and this was the encoding standards used for Win 9x systems, while Unicode is a newer standard which is default for NT based systems like WinNT,2000,XP. Unicode is also supposed to run faster on those systems because of native OS kernel support.
 
Well, anyway.. Whatever encoding I used, that was predefined in VB, didnt take the chars i needed, but works a charm now..

god system that uses such encodings :mad:
 
I did the Notepad test and see the problem. StreamReader defaults to System.Text.Encoding.UTF8, so it is capable of reading those chars, but Notepad defaults to saving as ANSI, so unicode won't recognize those chars from that encoding. If you force Notepad (or other app) to save with Unicode encoding the StreamReader will also read it correctly with Unicode. Your solution is correct with the source file you have.
 
Back
Top