Nicholas Paldino [.NET/C# MVP] wrote:
Amy,
Well, it's possible that you are reading the file correctly from
UTF-8, but the font for the console doesn't support those characters.
What is the font that you are using and does it support those characters?
In testing I decided to print each char to the screen along with its
byte value. The code is merely a (int)c where c is a char.
When using StreamReader with Encoding.UTF8 the ñ gets displayed as a ?
with a code of 65535
When using StreamReader with Encoding.Default the ñ gets displayed as a
ñ with a code of 241
When using FileStream with no encoding (don't believe you can set it)
and than printing the characters of the bytes ñ gets displayed as a ñ
with a code of 241.
When attempting to convert the byte array returned from the FileStream
to a String in UTF8 via below the sting does not convert properly (I get
the ? for the accented characters).
UTF8Encoding temp = new UTF8Encoding( true );
Console.WriteLine( temp.GetString( b ) );
However, if I do
Console.WriteLine( System.Text.Encoding.Default.GetString( b ) );
It prints correctly.
I have read that using "Encoding.Default" is not good - however it seems
to be the only thing that works. I know the characters are for the most
part being read in correctly especially with FileStream. It just seems
like I am lost on what to do about the encoding of them.
Thoughts?
Darrell