encoding problem on ASP .net page

G

Guest

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
 
M

Martin Dechev

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
 
J

Joerg Jooss

WEIWEIWEI said:
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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top