storing unicode in byte array?

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
 
G

GhostInAK

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
 
G

grawsha2000

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

Ahmed

Hi grawsha,

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

Cheers,
Ahmed
 
H

Herfried K. Wagner [MVP]

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

grawsha2000

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top