From: darren kirby Date: 2006-06-23T23:23:26+09:00 Subject: Re: ascii representation of unicode string? --nextPart2730957.KaNmrRNY05 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline quoth the Paul Battley: > > 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 =3D > "W\000M\000/\000T\000r\000a\000c\000k\000N\000u\000m\000b\000e\000r\000\0= 00 >\000\003" ic =3D Iconv.new("US-ASCII//IGNORE", "UTF-16LE") > p (ic.iconv(s+' '))[0..-2] # =3D> "WM/TrackNumber" Hi Paul, This seems to be working quite nicely, after playing around for a bit. A fe= w=20 of my test files were throwing "Iconv::InvalidCharacter" errors on some=20 strings, but when I change the "(s+' ')" to "(s)" it works fine. Then, of=20 course, the strings that originally worked start throwing the error. So, I = do=20 this: begin textString =3D @ic.iconv(data+' ')[0..-2] rescue textString =3D @ic.iconv(data)[0..-2] end Yesir, I am really just mashing code together until I see the results I am= =20 looking for... I wonder though, the docs lead me to believe the iconv library is UNIX only= =2E=20 Is this true? I really need a cross-platform solution, but don't have a win= 32=20 box to try on... Thanks very much, > Paul. =2Dd =2D-=20 darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." =2D Dennis Ritchie and Ken Thompson, June 1972 --nextPart2730957.KaNmrRNY05 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iD8DBQBEm/k9wPD5Cr/3CJgRAtmzAKDJoUTzyWW50X7nwFEx++7hMV2bagCeIlXw b5ktNMGgfC0eBNpGUVeYk8U= =6CZZ -----END PGP SIGNATURE----- --nextPart2730957.KaNmrRNY05--