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 StringGetVowelAndConsonentCount( string as CFStringRef, vowels as ^long, consonents as ^long )
void local fn StringGetVowelAndConsonantCount( string as CFStringRef, vowels as ^long, consonents as ^long )
CFCharacterSetRef vowelSet = fn CharacterSetWithCharactersInString( @"aeiou" )
CFCharacterSetRef vowelSet = fn CharacterSetWithCharactersInString( @"aeiou" )
CFMutableCharacterSetRef consonentSet = fn MutableCharacterSetLetterSet
CFMutableCharacterSetRef consonantSet = fn MutableCharacterSetLetterSet
fn MutableCharacterSetRemoveCharactersInString( consonentSet, @"aeiou" )
fn MutableCharacterSetRemoveCharactersInString( consonantSet, @"aeiou" )
*vowels = len( fn StringComponentsSeparatedByCharactersInSet( string, vowelSet ) ) - 1
*vowels = len( fn StringComponentsSeparatedByCharactersInSet( string, vowelSet ) ) - 1
*consonents = len( fn StringComponentsSeparatedByCharactersInSet( string, consonentSet ) ) - 1
*consonents = len( fn StringComponentsSeparatedByCharactersInSet( string, consonantSet ) ) - 1
end fn
end fn


void local fn DoIt
void local fn DoIt
long index, vowels, consonents
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 StringGetVowelAndConsonentCount( strings[index], @vowels, @consonents )
fn StringGetVowelAndConsonantCount( strings[index], @vowels, @consonants )
NSLog(@"\"%@\" contains %ld vowels and %ld consonents",strings[index],vowels,consonents)
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 consonents
"abcdefghijklmnop345qrstuvwxyz" contains 5 vowels and 21 consonants
"The quick brown fox jumps over the lazy dog" contains 11 vowels and 24 consonents
"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 consonents
"The answer my friend is blowing in the wind" contains 11 vowels and 24 consonants
</pre>
</pre>




=={{header|Go}}==
=={{header|Go}}==