Character encoding

  • Thread starter Thread starter seb
  • Start date Start date
S

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
 
seb said:
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
incorrectly. The idea of 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.
 
Back
Top