From: Holden Glova Date: 2002-03-30T06:15:53+09:00 Subject: Re: String operation -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 30 Mar 2002 05:52, Dat Nguyen wrote: > Hello all,�Is there an�efficient way to replace multiple characters in a > string given the positions and the lengths of strings to be replaced. For > instance�to modify the�string 'Hello World"�to "Hallo Welt" in one > operation, that is to change only the partial strings 'e' with 'a', and > 'or'�with 'e', and 'd' with 't'. Or to modify the string 'New York' to > 'NY',� 'December' to 'Dec'.�Thanks,Dat > > Join the world's largest e-mail service with MSN Hotmail. Click Here Hi Dat, Each one of the needs you describe above requires a different solution because they are all different problems. The last two examples are the easiest to solve so I'll start you off with those :) irb(main):002:0> "December"[0,3] "Dec" irb(main):008:0> "New York".split.collect { |word| word[0].chr }.join "NY" - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8pNrY+mF116Lw2cQRApokAJwLMgCTU18AQpjTHPTJp3ufsRCM8QCdH2X9 RSrSGYBOrNLzPNTfKTR4aBI= =sqVL -----END PGP SIGNATURE-----