sentence count : Word counter « File Directory « Ruby






sentence count


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

puts "#{line_count} lines"

sentence_count = text.split(/\.|\?|!/).length
puts "#{sentence_count} sentences"

 








Related examples in the same category

1.File word counter
2.Counting Sentences and Paragraphs
3.paragraph count