Hi!
Is there any way to decode a UCS-2 string with ruby?
Thanks!
Ciao!
Florian
Hi!
Is there any way to decode a UCS-2 string with ruby?
Thanks!
Ciao!
Florian
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.
On 8/1/06, Florian Weber <csshsh@gmail.com> wrote:
Hi!
Is there any way to decode a UCS-2 string with ruby?
Florian Weber wrote:
Hi!
Is there any way to decode a UCS-2 string with ruby?
require 'iconv'
=> true
Iconv.iconv("UTF-8", "UCS-2", "\0a\0b")
=> ["ab"]
Cheers,
Dave
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.
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?> require 'iconv'
=> true
> Iconv.iconv("UTF-8", "UCS-2", "\0a\0b")
=> ["ab"]
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