Home All Groups Group Topic Archive Search About

storing unicode in byte array?

Author
21 Jun 2006 6:22 PM
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

Author
21 Jun 2006 6:59 PM
GhostInAK
Hello grawsha2***@yahoo.com,

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

Show quoteHide quote
> 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
Author
21 Jun 2006 7:07 PM
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.


GhostInAK wrote:
Show quoteHide quote
> Hello grawsha2***@yahoo.com,
>
> 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
>
> > 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
Author
21 Jun 2006 8:22 PM
Ahmed
Hi grawsha,

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

Cheers,
Ahmed

grawsha2***@yahoo.com wrote:
Show quoteHide quote
> 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.
>
>
> GhostInAK wrote:
> > Hello grawsha2***@yahoo.com,
> >
> > 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
> >
> > > 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
Author
17 Jul 2006 11:24 AM
grawsha2000
GhostInAK wrote:
> Hello grawsha2***@yahoo.com,
>
> 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
Author
21 Jun 2006 8:34 PM
Herfried K. Wagner [MVP]
<grawsha2***@yahoo.com> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>