+ 3
Letter Counter
I want to count only letters in text, how should I exclude symbols like dots? lcount - number of letters text.each_char { |char| lcount += 1 if idontknowwhattodo}
2 Answers
+ 4
If current char is equal to dot then continue else increment letter count
0
you can use regexp to strip all punctuation and special characters, leaving only alphanumeric characters and spaces, so that it's easy to count.
i give you an example.
class String
def to_alphanumeric
gsub(/[^\w\s]/, '')
end
end
count = test.to_alphanumeric.split(/ /).size
maybe you shoud test it first