Jesús Gabriel y Galán
1/9/2008 9:31:00 AM
On Jan 9, 2008 2:44 AM, Ckvok Kovsky <mr.oliveira@gmail.com> wrote:
> Hello. I'm a ruby newbie.
> I'd like to make a "mass substitution" version of gsub, like in the sed
> example:
>
> $echo "=E1stur=E3kols=E9" | sed -e 'y/=E1=E3=E9/aae/'
> asturakolse
>
> Alike, I'd do something like "=E3ol=E9l=FC".gsubm("=E3=E9=FC","aeu") whic=
h would
> return "aolelu"
> p "Leein=E1d".gsubm("=E1",'a')a
>
> I didn't get success in any case. I've searched a lot also, but couldn't
> find any solution.
Maybe tr will work for you:
irb(main):012:0> "abcdefghijk".tr "abc", "123"
=3D> "123defghijk"
It supports character ranges, and padding the second argument
with its last character if it's shorter than the first one:
"hello".tr('aeiou', '*') #=3D> "h*ll*"
"hello".tr('^aeiou', '*') #=3D> "*e**o"
"hello".tr('el', 'ip') #=3D> "hippo"
"hello".tr('a-y', 'b-z') #=3D> "ifmmp"
I was having some problems testing your cases, I think because of the
strange chars, maybe that's the source of your problems too?
Hope this helps,
Jesus.