A stupid question?

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!?’
puts str.count(“a-zA-z”, “^aeiou”)

–output:–
7

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”.

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

n Fri, Dec 21, 2012 at 9:56 AM, Brian C. [email protected]
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 Sat, Dec 22, 2012 at 7:17 AM, tamouse mailing lists
[email protected] wrote:

=> 7
=> 28
… and that counts non-alphas.

s.scan(/[[:alpha:]]+/i).join.scan(/[^aeiou]+/i).join.size