storing unicode in byte array?

  • Thread starter Thread starter grawsha2000
  • Start date Start date
G

grawsha2000

Hi,

I'm trying to save unicode chars. in byte array. The problem is when I
try retrieve the saved chars back from the array I get different chars
from the one I saved.

Code:

dim uni as system.text.encoding=encoding.unicode
dim byte1 as byte()=uni.getbytes(1607) '1607 is the unicode
represnt. of an arabic letter

'now retrieve saved char. (number) from byte1()

messagebox.show(byte1(0) & byte1(1)) ' it shows different
value..??

Now, may be I did not get byte array clear. But it is a series of
bytes to save number 0-255, so what I did here is I just saved the
unicode numbers contiguously.

MTIA,
Grawsha
 
Hello (e-mail address removed),

First off, Turn Option Strict On. Second, read the documentation. Guessing
only makes you look stoopid.

The Encoding.GetBytes() function does not take a single numerical value.

-Boo
 
Ok, may be you did not understand my post well.

If I pass an arabic letter to the method, it will appear as junk in
non-arbic supported browser. That is why I indicated the number for
the letter.
 
Hi grawsha,

Well, you need to call Encoding.Unicode.GetChars to convert bytes back
to chars.

Cheers,
Ahmed
 
I'm trying to save unicode chars. in byte array. The problem is when I
try retrieve the saved chars back from the array I get different chars
from the one I saved.

Code:

dim uni as system.text.encoding=encoding.unicode
dim byte1 as byte()=uni.getbytes(1607) '1607 is the unicode
represnt. of an arabic letter

Try to pass 'ChrW(1607)' to 'GetBytes'. Note that 'Encoding.Unicode' means
UTF-16.
 
GhostInAK said:
Hello (e-mail address removed),

First off, Turn Option Strict On. Second, read the documentation. Guessing
only makes you look stoopid.

The Encoding.GetBytes() function does not take a single numerical value.

-Boo


LOL!! Reading some posts made me sure that there are alot stupid
people!!



Grawsha
 
Back
Top