How to remove vowels from a string in Ruby?

1

I have the following array:

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

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
source

1 answer

2

You could just use something like this:

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

Or better:

string.tr('aeiou', '')

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

string.delete('aeiou')

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

a = nombres.map { |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
source