Count how many vowels and consonants occur in a string: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 653: | Line 653: | ||
<syntaxhighlight lang="futurebasic">include "NSLog.incl" |
<syntaxhighlight lang="futurebasic">include "NSLog.incl" |
||
void local fn |
void local fn StringGetVowelAndConsonantCount( string as CFStringRef, vowels as ^long, consonents as ^long ) |
||
CFCharacterSetRef vowelSet = fn CharacterSetWithCharactersInString( @"aeiou" ) |
CFCharacterSetRef vowelSet = fn CharacterSetWithCharactersInString( @"aeiou" ) |
||
CFMutableCharacterSetRef |
CFMutableCharacterSetRef consonantSet = fn MutableCharacterSetLetterSet |
||
fn MutableCharacterSetRemoveCharactersInString( |
fn MutableCharacterSetRemoveCharactersInString( consonantSet, @"aeiou" ) |
||
*vowels = len( fn StringComponentsSeparatedByCharactersInSet( string, vowelSet ) ) - 1 |
*vowels = len( fn StringComponentsSeparatedByCharactersInSet( string, vowelSet ) ) - 1 |
||
*consonents = len( fn StringComponentsSeparatedByCharactersInSet( string, |
*consonents = len( fn StringComponentsSeparatedByCharactersInSet( string, consonantSet ) ) - 1 |
||
end fn |
end fn |
||
void local fn DoIt |
void local fn DoIt |
||
long index, vowels, |
long index, vowels, consonants |
||
CFArrayRef strings = @[@"abcdefghijklmnop345qrstuvwxyz", |
CFArrayRef strings = @[@"abcdefghijklmnop345qrstuvwxyz", |
||
Line 669: | Line 669: | ||
for index = 0 to len(strings) - 1 |
for index = 0 to len(strings) - 1 |
||
fn |
fn StringGetVowelAndConsonantCount( strings[index], @vowels, @consonants ) |
||
NSLog(@"\"%@\" contains %ld vowels and %ld |
NSLog(@"\"%@\" contains %ld vowels and %ld consonants",strings[index],vowels,consonants) |
||
next |
next |
||
end fn |
end fn |
||
Line 679: | Line 679: | ||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
"abcdefghijklmnop345qrstuvwxyz" contains 5 vowels and 21 |
"abcdefghijklmnop345qrstuvwxyz" contains 5 vowels and 21 consonants |
||
"The quick brown fox jumps over the lazy dog" contains 11 vowels and 24 |
"The quick brown fox jumps over the lazy dog" contains 11 vowels and 24 consonants |
||
"The answer my friend is blowing in the wind" contains 11 vowels and 24 |
"The answer my friend is blowing in the wind" contains 11 vowels and 24 consonants |
||
</pre> |
</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |