By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,717 Members | 2,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,717 IT Pros & Developers. It's quick & easy.

Character encoding

P: n/a
seb
Hi all,

I work on a translation module and I need to encode different
characters from different charset.
I've got an Access database that countains the different translations.
When I display the content of it, it works well (I set the page
charset to utf-8).
Now, I'd like to get each character code. For that, I use
Encoding.GetBytes function, as following:

'let's say I work with the greek part:

targetEncoding = Encoding.GetEncoding(1253)
newStringArray = targetEncoding.GetBytes(myGreekString)
For i = 0 To newStringArray.Length - 1
newGreekString = newGreekString & "&#" & newStringArray(i) & ";"
Next i

Unfortunaly, I don't get the correct character code in my
newGreekString variable.

I can't see what I'm doing wrong. Any idea please ?

thx in advance,

seb
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
seb <s.******@megalos.net> wrote:
I work on a translation module and I need to encode different
characters from different charset.
I've got an Access database that countains the different translations.
When I display the content of it, it works well (I set the page
charset to utf-8).
Now, I'd like to get each character code. For that, I use
Encoding.GetBytes function, as following:

'let's say I work with the greek part:

targetEncoding = Encoding.GetEncoding(1253)
newStringArray = targetEncoding.GetBytes(myGreekString)
For i = 0 To newStringArray.Length - 1
newGreekString = newGreekString & "&#" & newStringArray(i) & ";"
Next i
Firstly, use StringBuilder for this kind of loop - otherwise your
performance will be awful.
Unfortunaly, I don't get the correct character code in my
newGreekString variable.

I can't see what I'm doing wrong. Any idea please ?


Assuming you're trying to generate XML, you're using &#xxx;
incorrectly. The idea of &#xxx; is that xxx is the Unicode value of the
character, not a byte-encoded value. To get the Unicode value as an
integer, you just need to cast from Character to Int32 - you don't need
to use your encoding at all.

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

P: n/a
thanks Jon, that's exactly what I was trying to do !

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.