How to remove vowels from a string in Ruby?


I have the following array:

nombres = ["Violeta", "Andino", "Clemente", "Javiera", "Paula", "Pia", "Ray"]
a =

And I would like to create another one and store it in the variable by removing all the vowels from the names.

Using .map and .gsub

asked by Upset Grade 04.05.2018 в 21:08

1 answer


You could just use something like this:

string.gsub(/[aeiou]/, '')

Or better:'aeiou', '')

And the best tool to remove characters in a string is ...


As suggested by @Gerry, you can do it with map :

a = { |nombre| nombre.delete('aeiou') }

SO source: Ruby code for deleting the vowels in a string   

Here is a Post that contains a fairly broad solution with several examples:

answered by 04.05.2018 / 21:22