G
Gijs Nijholt
Hi (again),
I have a multi-dimensional array.. walking through an incoming string
like this:
def translate(msg)
some_alphabet = [ ["a","A"], ["b","B"], ["c","C"], ["d","D"] ]
msg.split(//).inject("") { |result, char|
result += some_alphabet[2][1]
}
end
This replaces everything in msg with a "C", as it's the third one in the
array.
But I'm looking for a way to replace not by integer/index but by char,
like:
some_alphabet["c"][1]
I hope you know what I mean.. I looked at at() and find() and scan() but
neither seems to fit this task?
Thanks!
Gijs
I have a multi-dimensional array.. walking through an incoming string
like this:
def translate(msg)
some_alphabet = [ ["a","A"], ["b","B"], ["c","C"], ["d","D"] ]
msg.split(//).inject("") { |result, char|
result += some_alphabet[2][1]
}
end
This replaces everything in msg with a "C", as it's the third one in the
array.
But I'm looking for a way to replace not by integer/index but by char,
like:
some_alphabet["c"][1]
I hope you know what I mean.. I looked at at() and find() and scan() but
neither seems to fit this task?
Thanks!
Gijs