By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,537 Members | 1,750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,537 IT Pros & Developers. It's quick & easy.

UTF encoding and StreamWriter

P: n/a
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

Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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?

--
Happy Coding!
Morten Wennevik [C# MVP]
"ar******@gmail.com" wrote:
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

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.