473,396 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

string encoding problem

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
Jul 21 '05 #1
6 6511
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
Jul 21 '05 #2
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
Jul 21 '05 #3
Hi

What I am doing is
I got a form in a utf-8 page
I get data from that form, and want to submit the data in email using a 3rd party compoent in Big5 format
so that's what I am now working on

originally using the .NET MailMessage Class, I can do sth like
message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312")

but now I can't do that so that's y I;d like to change the encoding of the string I go

Thanks for you help
Jul 21 '05 #4
Hi

What I am doing is
I got a form in a utf-8 page
I get data from that form, and want to submit the data in email using a 3rd party compoent in Big5 format
so that's what I am now working on

originally using the .NET MailMessage Class, I can do sth like
message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312")

but now I can't do that so that's y I;d like to change the encoding of the string I go

Thanks for you help
Jul 21 '05 #5
WEIWEIWEI <an*******@discussions.microsoft.com> wrote:
What I am doing is:
I got a form in a utf-8 page.
I get data from that form, and want to submit the data in email using
a 3rd party compoent in Big5 format.
so that's what I am now working on.
Right. The fact that the form is in UTF-8 is irrelevant then.
originally using the .NET MailMessage Class, I can do sth like:
message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");

but now I can't do that so that's y I;d like to change the encoding
of the string I got


You can't change the encoding of a string - a string itself hasn't
*got* an encoding.

Now, why can't you set the BodyEncoding any more?

What format are you submitting the data to the 3rd party component in?
If it's as a byte array, you can get the Big5-encoded byte array of
your string. If it's as a string, you'll have to find some other way of
telling it to use Big5.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #6
WEIWEIWEI <an*******@discussions.microsoft.com> wrote:
What I am doing is:
I got a form in a utf-8 page.
I get data from that form, and want to submit the data in email using
a 3rd party compoent in Big5 format.
so that's what I am now working on.
Right. The fact that the form is in UTF-8 is irrelevant then.
originally using the .NET MailMessage Class, I can do sth like:
message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");

but now I can't do that so that's y I;d like to change the encoding
of the string I got


You can't change the encoding of a string - a string itself hasn't
*got* an encoding.

Now, why can't you set the BodyEncoding any more?

What format are you submitting the data to the 3rd party component in?
If it's as a byte array, you can get the Big5-encoded byte array of
your string. If it's as a string, you'll have to find some other way of
telling it to use Big5.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Austin | last post by:
Hello I am wondering if anyone knows if there is a way to store string literals within an XML tag. For instance I would like to store HTML formatting data for an attribute but it keeps...
7
by: john | last post by:
On my form i have a message box called txtItemDesc that displays the french phrase qualité Père Noël. Now then when i run this code on that text box: Dim chrArr() As Char chrArr =...
8
by: David Thielen | last post by:
Hi; I have a string that is an xml file. It starts with <?xml encoding='utf-8'... and it has the utf-8 2-byte sequences as 2 chars. How do I get that into an XPathDocument where the 2-char...
6
by: Marco Herrn | last post by:
Hi, I need to serialize an object into a string representation to store it into a database. So the SOAPFormatter seems to be the right formatter for this purpose. Now I have the problem that...
8
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
6
by: WEIWEIWEI | last post by:
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...
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
8
by: Jeremy Kitchen | last post by:
I have encoded a string into Base64 for the purpose of encryption. I then later decrypted it and converted it back from Base64 the final string returns with four nothing characters. "pass" what...
5
by: sniipe | last post by:
Hi, I have a problem with unicode string in Pylons templates(Mako). I will print first char from my string encoded in UTF-8 and urllib.quote(), for example string '£ukasz': ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.