WEIWEIWEI <an*******@discussions.microsoft.com> wrote:
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);
}
A string is just a sequence of characters - it doesn't have an
encoding, really. (Internally it's in UTF-16, but that's not really
important.)
What you're doing above is finding the UTF-8 encoded byte sequence for
a string, and then trying to decode that as if it were a Big5 encoded
byte sequence.
The browser should be setting its content type on the response, and
submitting the data in the encoding it specifies. ASP.NET will decode
that appropriately, and then you've got a string - you shouldn't need
to worry beyond that.
Now, what problem are you actually trying to solve?
Look at these articles for more information and ideas:
http://www.pobox.com/~skeet/csharp/unicode.html http://www.pobox.com/~skeet/csharp/d...ngunicode.html
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too