I want to replace all these characters: 'àáäâãèéëẽêìíïîĩòóöôõùúüûũñç'
to 'aaaaaeeeeeiiiiiooooouuuuunc'
.
Is there a effective way to do this in Ruby? I was thinking about loop each character, but it's not effective.
Thanks.
I would use tr
which is faster than a Regexp when replacing single characters:
string = 'hàllò wörld'
string.tr('àáäâãèéëẽêìíïîĩòóöôõùúüûũñç', 'aaaaaeeeeeiiiiiooooouuuuunc')
#=> '"hallo world"'
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