From: Tony Arcieri Date: 2012-07-04T02:31:10+09:00 Subject: Re: Remove vowels from a string --000e0cdfce369e077004c3f04717 Content-Type: text/plain; charset=ISO-8859-1 Try str.gsub(/[aeiou]/i, '') On Tue, Jul 3, 2012 at 10:22 AM, Joao Silva wrote: > Hi all. > > I'm trying to make a program that removes all the vowels in a string > entered, but no I'm doing wrong. This is the code I am doing: > > ########################################################## > def remove_vowels(string) > vowels = %w{a e i o u A E I O U} > str = "" > for i in 0..string.length > if not string[i]==vowels[i] then > str[i]=string[i] > end > end > return str > end > > puts "Enter a string:: " > string=gets.chomp.to_s > > s=remove_vowels(string) > > puts "Original string: #{string}" > puts "String without vowels >> #{s}" > ############################################################## > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > > -- Tony Arcieri --000e0cdfce369e077004c3f04717 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Try str.gsub(/[aeiou]/i, '')

On T= ue, Jul 3, 2012 at 10:22 AM, Joao Silva <lists@ruby-forum.com> wrote:
Hi all.

I'm trying to make a program that removes all the vowels in a string entered, but no I'm doing wrong. This is the code I am doing:

##########################################################
def remove_vowels(string)
=A0 vowels =3D %w{a e i o u A E I O U}
=A0 str =3D ""
=A0 for i in 0..string.length
=A0 =A0 =A0 =A0 if not string[i]=3D=3Dvowels[i] then
=A0 =A0 =A0 =A0 =A0 =A0 str[i]=3Dstring[i]
=A0 =A0 =A0 =A0 end
=A0 =A0 end
=A0 =A0 return str
end

puts "Enter a string:: "
string=3Dgets.chomp.to_s

s=3Dremove_vowels(string)

puts "Original string: #{string}"
puts "String without vowels >> #{s}"
##############################################################

Thanks.

--
Posted via http://= www.ruby-forum.com/.




-- Tony Arcieri

--000e0cdfce369e077004c3f04717--