473,382 Members | 1,647 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,382 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 6507
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': ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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...

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.