From: Paul Battley Date: 2006-06-23T20:31:01+09:00 Subject: Re: ascii representation of unicode string? On 22/06/06, darren kirby wrote: > I am unpacking some unicode strings from a binary file. I have a string like: > > "W\000M\000/\000T\000r\000a\000c\000k\000N\000u\000m\000b\000e\000r\000\000\000\003" > > and I need to turn it into: > > "WM/TrackNumber" ... > So can I extract an ascii representation of this string? I will admit I don't > know the first thing about unicode and I may be totally lost here... Here's a reliable way to do it with Iconv: require 'iconv' s = "W\000M\000/\000T\000r\000a\000c\000k\000N\000u\000m\000b\000e\000r\000\000\000\003" ic = Iconv.new("US-ASCII//IGNORE", "UTF-16LE") p (ic.iconv(s+' '))[0..-2] # => "WM/TrackNumber" Paul.