Removing punctation


#1



You did it!

Having completed the excersise, i have the problem still that it sees a word with punctation as a different word w/o it, same goes for word w capitals.. I tried to use some gsub! but i cant get it to work. where in the code do i put it?
gets.chomp.gsub!(/[,.]/, "" ) seems to work, but whenever i add .downcase! it gives error

puts "Put in a text"
text = gets.chomp.gsub!(/[,.]/, "" )
words = text.split(" ")
frequencies = Hash.new(0)
words.each { |word| frequencies[word] += 1 }
frequencies = frequencies.sort_by { |a,b| b }
frequencies.each { |book,count| puts book + " " + count.to_s }


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.