Encoding.Default and Encoding.UTF8

Discussion in 'ASP .Net' started by Hardy Wang, Jun 8, 2004.

  1. Hardy Wang

    Hardy Wang Guest

    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
    Hardy Wang, Jun 8, 2004
    #1
    1. Advertising

  2. Hardy Wang <> 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 - <>
    http://www.pobox.com/~skeet
    If replying to the group, please do not mail me too
    Jon Skeet [C# MVP], Jun 9, 2004
    #2
    1. Advertising

  3. Hardy Wang

    Hardy Wang Guest

    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]" <> wrote in message
    news:...
    > Hardy Wang <> 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 - <>
    > http://www.pobox.com/~skeet
    > If replying to the group, please do not mail me too
    Hardy Wang, Jun 9, 2004
    #3
  4. Hardy Wang <> 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 - <>
    http://www.pobox.com/~skeet
    If replying to the group, please do not mail me too
    Jon Skeet [C# MVP], Jun 9, 2004
    #4
  5. Hardy Wang

    Hardy Wang Guest

    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]" <> wrote in message
    news:...
    > Hardy Wang <> 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 - <>
    > http://www.pobox.com/~skeet
    > If replying to the group, please do not mail me too
    Hardy Wang, Jun 9, 2004
    #5
  6. Hardy Wang <> 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 - <>
    http://www.pobox.com/~skeet
    If replying to the group, please do not mail me too
    Jon Skeet [C# MVP], Jun 9, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Erik Sandblom

    open with encoding(utf8) takes forever

    Erik Sandblom, May 28, 2004, in forum: Perl
    Replies:
    0
    Views:
    535
    Erik Sandblom
    May 28, 2004
  2. Christian Hanke

    Tomcat4: Default Page Encoding UTF8

    Christian Hanke, Nov 5, 2003, in forum: Java
    Replies:
    1
    Views:
    535
    Sudsy
    Nov 5, 2003
  3. Replies:
    2
    Views:
    591
    Rohit Gupta
    Jun 20, 2005
  4. weheh
    Replies:
    6
    Views:
    772
    John Nagle
    Dec 24, 2007
  5. gry
    Replies:
    2
    Views:
    707
    Alf P. Steinbach
    Mar 13, 2012
Loading...

Share This Page