Encoding.Default and Encoding.UTF8

  • Thread starter Thread starter Hardy Wang
  • Start date Start date
H

Hardy Wang

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.
 
Hardy Wang said:
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.
 
Thanks,
Anybody knows are there any characters in French and Spanish greater than
128 ASCII code?
 
Hardy Wang said:
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?
 
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!
 
Hardy Wang said:
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.
 
Back
Top