[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

csshsh@gmail.com

7/31/2006 10:47:00 PM

Hi!

Is there any way to decode a UCS-2 string with ruby?

Thanks!

Ciao!
Florian

4 Answers

Dido Sevilla

8/1/2006 2:31:00 AM

0

On 8/1/06, Florian Weber <csshsh@gmail.com> wrote:
> Hi!
>
> Is there any way to decode a UCS-2 string with ruby?
>

Decode to what? You're probably looking for iconv. There's a Ruby
binding for that in the standard library, and it should be able to
convert your UCS-2 to almost anything. If you just want to convert it
to UTF-8, I believe the pack/unpack methods for strings and arrays
ought to be able to do the trick.

dave.burt

8/1/2006 4:44:00 AM

0

Florian Weber wrote:
> Hi!
>
> Is there any way to decode a UCS-2 string with ruby?

irb> require 'iconv'
=> true
irb> Iconv.iconv("UTF-8", "UCS-2", "\0a\0b")
=> ["ab"]

Cheers,
Dave

Paul Battley

8/1/2006 8:37:00 AM

0

On 01/08/06, dave.burt@gmail.com <dave.burt@gmail.com> wrote:
> Florian Weber wrote:
> > Hi!
> >
> > Is there any way to decode a UCS-2 string with ruby?
>
> irb> require 'iconv'
> => true
> irb> Iconv.iconv("UTF-8", "UCS-2", "\0a\0b")
> => ["ab"]

It's probably worth specifying endianness for portability:

Iconv.iconv("UTF-8", "UCS-2BE", "\0a\0b")

However, are you sure you want UCS-2, and not its superset UTF-16? In
my experience, specifying UCS-2 instead of UTF-16 is almost always a
bug.

Paul.

Tim Bray

8/1/2006 6:32:00 PM

0

Paul Battley wrote:
> However, are you sure you want UCS-2, and not its superset UTF-16? In
> my experience, specifying UCS-2 instead of UTF-16 is almost always a
> bug.
In fact, if you want to be pedantic (and when it comes to character
encoding, pedantic is good) UCS-2 doesn't actually exist any more, last
time I checked. Paul is right, you really mean UTF-16. -Tim