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

Encoding.Default and Encoding.UTF8

P: n/a
Hi,
I have following code:
Encoding mode; // Encoding.Default or Encoding.UTF8
FileStream sb = new FileStream(fullPathAndFileName, FileMode.Create);
StreamWriter sw = new StreamWriter(sb, mode);
sw.Write(textContent);
sw.Close();

My question is under what situation, the saved files are different by
calling Encoding.Default and Encoding.UTF8.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hardy Wang <ha********@marketrend.com> wrote:
I have following code:
Encoding mode; // Encoding.Default or Encoding.UTF8
FileStream sb = new FileStream(fullPathAndFileName, FileMode.Create);
StreamWriter sw = new StreamWriter(sb, mode);
sw.Write(textContent);
sw.Close();

My question is under what situation, the saved files are different by
calling Encoding.Default and Encoding.UTF8.


They'll almost certainly be different for any string containing non-
ASCII characters. They're likely to be the same for any string
containing solely ASCII characters.

See http://www.pobox.com/~skeet/csharp/unicode.html for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

P: n/a
Thanks,
Anybody knows are there any characters in French and Spanish greater than
128 ASCII code?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Hardy Wang <ha********@marketrend.com> wrote:
I have following code:
Encoding mode; // Encoding.Default or Encoding.UTF8
FileStream sb = new FileStream(fullPathAndFileName, FileMode.Create);
StreamWriter sw = new StreamWriter(sb, mode);
sw.Write(textContent);
sw.Close();

My question is under what situation, the saved files are different by
calling Encoding.Default and Encoding.UTF8.


They'll almost certainly be different for any string containing non-
ASCII characters. They're likely to be the same for any string
containing solely ASCII characters.

See http://www.pobox.com/~skeet/csharp/unicode.html for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3

P: n/a
Hardy Wang <ha********@marketrend.com> wrote:
Anybody knows are there any characters in French and Spanish greater than
128 ASCII code?


There are no such thing as ASCII values above 127. What did you mean,
exactly?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

P: n/a
Let me make it clear, I am just wandering if there are any characters in
French and Spanish non ASCII character.

What I would like to know is, if there are such characters, by using
Encoding.Default (US English or Canada English as Win2000's locale) to save
to a text file, will these characters be lost?

Thanks!

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Hardy Wang <ha********@marketrend.com> wrote:
Anybody knows are there any characters in French and Spanish greater than 128 ASCII code?


There are no such thing as ASCII values above 127. What did you mean,
exactly?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5

P: n/a
Hardy Wang <ha********@marketrend.com> wrote:
Let me make it clear, I am just wandering if there are any characters in
French and Spanish non ASCII character.
Certainly - any accented characters, to start with.
What I would like to know is, if there are such characters, by using
Encoding.Default (US English or Canada English as Win2000's locale) to save
to a text file, will these characters be lost?


Possibly. However, there are various characters in Encoding.Default
which *aren't* in ASCII, and which won't be lost.

I'd strongly recommend using UTF-8 if you have the opportunity,
however.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.