I want to find the successor of each element in my encoded string. For example K->M A->C etc.
string.each_char do |ch|
dummy_string<< ch.succ.succ
end
However this method translates y->aa.
Is there a method in Ruby that is like maketrans() in Python?
You seem to be looking for String#tr. Use like this: some_string.tr('a-zA-Z', 'c-zabC-ZAB')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With