David Vallner schrieb:

> 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:
> >
> > newdata = File.read('test').tr("\t", ',')
> > # => "a\000b\000c\000,\000\273\006,\0001\000"
> >
>
> 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 = '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
> Content-Disposition: inline;
> 	filename="signature.asc"
> Content-Description: OpenPGP digital signature
> X-Google-AttachSize: 188

Thanks Ross for the try, but it is not working,
tried for:

"\377\376B\001\363\000|\001k\000o\000\t\000k\000s\000i\000\005\001|\001k\000a\000\t\000c\000z\000B\001o\000w\000i\000e\000k\000\r\000\n\000B\001\005\001k\000a\000\t\000\t\000|\001d\000z\001b\000B\001o\000\r\000\n\000"
which is:

ko	ksika	czowiek
ナてa		ナシdナコbナP

-> (the same :))

the conversion should be:
ko,ksika,czowiek
ナてa,,ナシdナコbナP

but with the Iconv try:
ko,ksika,czowiek
愀簀稀漁

after swapping utf-8 to ucs-2le in the both iconv convertions, I get an
error message:
`iconv': "\377\376B\001ツセ |笘コk\000o\000\t\000k\000"...
(Iconv::IllegalSequence)


Any other suggestions highly appreciated.

Thanks
chris