Count how many vowels and consonants occur in a string: Difference between revisions

no edit summary
m (→‎{{header|Wren}}: Minor tidy)
No edit summary
 
Line 2,204:
Vowels: 22, 5 unique.
Other: 16, 2 unique.
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">use std::io ;
 
//string supposed to contain ascii letters only!
fn main() {
println!("Enter a string!");
let mut inline : String = String::new( ) ;
io::stdin( ).read_line( &mut inline ).unwrap( ) ;
let entered_line : &str = &*inline ;
let vowels = vec!['a' , 'e' , 'i' , 'o' , 'u' , 'A' , 'E' , 'I' ,
'O' , 'U'] ;
let numvowels = entered_line.trim( ).chars( ).filter( | c |
vowels.contains( c ) ).count( ) ;
let consonants = entered_line.trim( ).chars( ).filter( | c |
! vowels.contains( c ) && c.is_ascii_alphabetic( )).count( ) ;
println!("String {:?} contains {} vowels and {} consonants!" ,
entered_line.trim( ) , numvowels , consonants ) ;
}</syntaxhighlight>
{{out}}
<pre>
Enter a string!
Rust shares properties of procedural and functional languages!
String "Rust shares properties of procedural and functional languages!" contains 21 vowels and 33 consonants!
</pre>
 
258

edits