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
···
--
Posted via http://www.ruby-forum.com/.
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
--
Posted via http://www.ruby-forum.com/.
str = 'hello world'
puts str.count("^ae iou")
--output:--
7
--
Posted via http://www.ruby-forum.com/.
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
--
Posted via http://www.ruby-forum.com/\.
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".
--
Posted via http://www.ruby-forum.com/\.
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 forstr = '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
n Fri, Dec 21, 2012 at 9:56 AM, Brian Candler <lists@ruby-forum.com> wrote:
... and that counts non-alphas.
s.scan(/[[:alpha:]]+/i).join.scan(/[^aeiou]+/i).join.size
On Sat, Dec 22, 2012 at 7:17 AM, tamouse mailing lists <tamouse.lists@gmail.com> wrote:
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 forstr = '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