Remove special chars with String#tr
Sometimes you need cleaning data containing unicode characters.
One easy way to do it is with the strings tr method.
puts "Hola áéíóú".tr('áéíóú', 'aeiou') #> "Hola aeiou"
This is very simple and you can evan have the character mappings in an array:
char_maps = %w/áéíóú aeiou/
puts "Hola áéíóú".tr(*char_maps) #> "Hola aeiou"
Enjoy!
Written by Javier Guerra
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#