UTF encoding and StreamWriter

A

arunairs

Hi,
After writing the £ (pound sterling) symbol to a file using
StreamWriter using the default encoding UTF8, when I retrieve it the
file symbol £ gets changed. But when I use Encoding.Default in the
StreamWriter, I am able to retrieve the symbol without any issue.

Can you tell me why this is so? Microsoft recommend using UTF8 for
encoding, but it does not seem to work in this case.

thanks,

Arun
 
M

Morten Wennevik [C# MVP]

Hi Arun,

You are not saving and reading the file using the same Encoding.

If you do not specify encoding the StreamWriter/Reader will default to UTF8,
but other applications often default to the code page used by your current
locale, Encoding.Default (ANSI). For instance, Notepad uses ANSI encoding if
not told otherwise.

Check your reading/writing code. If both reading and writing uses UTF8, do
other parts of your program, or other applications, create the file in
question?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top