Paul Battley
8/1/2006 8:37:00 AM
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.