From: David Vallner Date: 2006-12-06T15:10:32+09:00 Subject: Re: replace delimiter in unicode encdoded file --------------enig4A00E1A3DAAB09EEF0C6DD3E Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Ross Bamford wrote: > On Mon, 2006-12-04 at 22:40 +0900, ciapecki wrote: >> Is there a way in ruby to: >> - open a file encoded in ucs-2le, >> - replace every occurance of '\t' (X'0009') with ',' (X'002c'), >> - and save it back in ucs-2le, without loosing any content? > But that strikes me as unnecessary when you could just do: >=20 > newdata =3D File.read('test').tr("\t", ',') > # =3D> "a\000b\000c\000,\000\273\006,\0001\000" >=20 Um. Other way around. *Old* data is in UCS-2LE, not in UTF-8, so it's not ASCII-transparent. Your iconv approach could work if you swapped around the encoding names, except you'd probably also have to involve a $KCODE =3D 'u' and require 'jcode' to avoid clobbering the possible cases= where in UTF8, 0x09 and 0x2c are part of a multibyte sequence. David Vallner --------------enig4A00E1A3DAAB09EEF0C6DD3E Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFdl7Sy6MhrS8astoRAuqhAJsFmHW9c9sVJaaGWeWoNpoZLTJbagCeNvTj 4AdaA5ybtotNf+Q0F4wKlsA= =MRcg -----END PGP SIGNATURE----- --------------enig4A00E1A3DAAB09EEF0C6DD3E--