I'm trying to find a way to count the consonants in a sentence. how would i go about that? i tried to use length - [aeiou]. but never got the result i was looking for
on 2012-12-21 01:41
on 2012-12-21 02:24
7stud -- wrote in post #1089771: > str = 'Hello, world!?' > puts str.count("a-zA-z", "^aeiou") > Whoops. That should be ... count("a-zA-Z", "^aeiou"). You can read that statement as: count() all the characters which are in the ranges "a-zA-Z" AND which are not "aeiou".
on 2012-12-21 16:56
Al Baker wrote in post #1089770: > I'm trying to find a way to count the consonants in a sentence. how > would i go about that? i tried to use length - [aeiou]. but never got > the result i was looking for >> str = 'Hello, world!?' >> str.scan(/[a-df-hj-np-tv-z]/i).size => 7 >> str.gsub(/[^a-df-hj-np-tv-z]/i,'').size => 7
on 2012-12-22 14:17
n Fri, Dec 21, 2012 at 9:56 AM, Brian Candler <lists@ruby-forum.com> wrote: > Al Baker wrote in post #1089770: >> I'm trying to find a way to count the consonants in a sentence. how >> would i go about that? i tried to use length - [aeiou]. but never got >> the result i was looking for > >>> str = 'Hello, world!?' >>> str.scan(/[a-df-hj-np-tv-z]/i).size > => 7 >>> str.gsub(/[^a-df-hj-np-tv-z]/i,'').size > => 7 (a is a vowel...) I'd suggest this: > s = 'Helloooo my wonderfuuuuul peeeopulllaaaa. IIII am come!!' => "Helloooo my wonderfuuuuul peeeopulllaaaa. IIII am come!!" > s.scan(/[^aeiou]+/i).join('') => "Hll my wndrfl pplll. m cm!!" > s.scan(/[^aeiou]+/i).join('').size => 28
on 2012-12-22 14:31
On Sat, Dec 22, 2012 at 7:17 AM, tamouse mailing lists <tamouse.lists@gmail.com> wrote: >> => 7 > => 28 ... and that counts non-alphas. s.scan(/[[:alpha:]]+/i).join.scan(/[^aeiou]+/i).join.size
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.