encoding problem on ASP .net page

Discussion in 'ASP .Net' started by =?Utf-8?B?V0VJV0VJV0VJ?=, Apr 16, 2004.

  1. Hi Al

    I'd like to encode a string submitted from a utf-8 form in a aspx page to big5
    Any ideas on how to do that
    I try sth like

    public static string unicode_big5(string src) {
    Encoding big5 = Encoding.GetEncoding("big5")
    Encoding unicode = Encoding.UTF8
    byte[] unicodeBytes = unicode.GetBytes(src)
    return big5.GetString(unicodeBytes)

    But it doesn't wor

    Thanks in advanc
     
    =?Utf-8?B?V0VJV0VJV0VJ?=, Apr 16, 2004
    #1
    1. Advertising

  2. Is the string in the memory ok? I mean are the characters what they are
    suposed to be? Remember that the strings are stored in the memory as
    unicode. Maybe in your case you should change your code to:

    public static string unicode_big5(string src)
    {
    Encoding big5 = Encoding.GetEncoding("big5");
    Encoding unicode = Encoding.Unicode; // CHANGED HERE
    byte[] unicodeBytes = unicode.GetBytes(src);
    return big5.GetString(unicodeBytes);
    }

    Anyway, as I don't know your problem or the purpose of your code I'm only
    guessing

    Hope this helps
    Martin
    "WEIWEIWEI" <> wrote in message
    news:...
    > Hi All
    >
    > I'd like to encode a string submitted from a utf-8 form in a aspx page to

    big5.
    > Any ideas on how to do that?
    > I try sth like:
    >
    > public static string unicode_big5(string src) {
    > Encoding big5 = Encoding.GetEncoding("big5");
    > Encoding unicode = Encoding.UTF8;
    > byte[] unicodeBytes = unicode.GetBytes(src);
    > return big5.GetString(unicodeBytes);
    > }
    > But it doesn't work
    >
    > Thanks in advance
    >
    >
     
    Martin Dechev, Apr 16, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?V0VJV0VJV0VJ?=

    Joerg Jooss Guest

    WEIWEIWEI wrote:
    > Hi All
    >
    > I'd like to encode a string submitted from a utf-8 form in a aspx
    > page to big5. Any ideas on how to do that?


    If you're web application is set up correctly, ASP.NET will correctly
    convert decode UTF-8 encoded bytes. Thus, all you need is a simple encoding
    of a System.String to Big5 *byte* representation.

    > I try sth like:
    >
    > public static string unicode_big5(string src) {
    > Encoding big5 = Encoding.GetEncoding("big5");
    > Encoding unicode = Encoding.UTF8;
    > byte[] unicodeBytes = unicode.GetBytes(src);
    > return big5.GetString(unicodeBytes);
    > }
    > But it doesn't work


    It can't. You're encoding Unicode characters using UTF-8 and try to decode
    that using Big5. There's no such thing as UTF-8 strings or Big5 strings --
    these are *byte* representations of characters. So when you say you need a
    Big5 representation, all you'll get is bytes:

    Encoding big5 = Encoding.GetEncoding("big5");
    byte[] bytes = big5.GetBytes(aString);

    Cheers,
    --
    Joerg Jooss
     
    Joerg Jooss, Apr 16, 2004
    #3
    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. Matthew Louden
    Replies:
    4
    Views:
    3,092
    Fahad Al Hadhrami
    Nov 24, 2003
  2. Hardy Wang

    Encoding.Default and Encoding.UTF8

    Hardy Wang, Jun 8, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    18,996
    Jon Skeet [C# MVP]
    Jun 9, 2004
  3. Replies:
    1
    Views:
    23,524
    Real Gagnon
    Oct 8, 2004
  4. =?Utf-8?B?UGV0ZXIy?=
    Replies:
    2
    Views:
    8,660
    =?Utf-8?B?UGV0ZXIy?=
    May 16, 2006
  5. Replies:
    2
    Views:
    398
Loading...

Share This Page