+ 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}

28th Feb 2017, 1:41 PM
Kuba Nawieśniak
Kuba Nawieśniak - avatar
2 Respostas
+ 4
If current char is equal to dot then continue else increment letter count
28th Feb 2017, 5:02 PM
Nəzər Nəsirzadə
Nəzər Nəsirzadə - avatar
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
1st Mar 2017, 3:51 PM
Steven Wang
Steven Wang - avatar