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. Advertisements

  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. Advertisements

  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. Advertisements

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,347
    Fahad Al Hadhrami
    Nov 24, 2003
  2. Ryan
    Replies:
    0
    Views:
    501
  3. =?Utf-8?B?TWFyaw==?=

    different encoding handling between old ASP and ASP.Net

    =?Utf-8?B?TWFyaw==?=, Jun 6, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    764
    Joerg Jooss
    Jun 8, 2005
  4. =?Utf-8?B?UGV0ZXIy?=
    Replies:
    2
    Views:
    8,914
    =?Utf-8?B?UGV0ZXIy?=
    May 16, 2006
  5. Dica
    Replies:
    2
    Views:
    758
  6. =?Utf-8?B?U3RlcGhhbiBCb21ob2x0?=

    Cookie Encoding/sharing ASP.Net and ASP

    =?Utf-8?B?U3RlcGhhbiBCb21ob2x0?=, Sep 26, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    2,365
    Michael Nemtsev, MVP
    Sep 26, 2007
  7. Matthew Louden

    how ASP.NET page gets user input from another ASP.NET page??

    Matthew Louden, Nov 22, 2003, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    348
    Fahad Al Hadhrami
    Nov 24, 2003
  8. Chuck
    Replies:
    0
    Views:
    392
    Chuck
    Jul 5, 2003
Loading...