File word counter : Word counter « File Directory « Ruby






File word counter



lines = File.readlines("text.txt")
line_count = lines.size
text = lines.join

puts "#{line_count} lines"

word_count = text.split.length
puts "#{word_count} words"

 








Related examples in the same category

1.Counting Sentences and Paragraphs
2.paragraph count
3.sentence count