Count how many vowels and consonants occur in a string: Difference between revisions
Count how many vowels and consonants occur in a string (view source)
Revision as of 23:33, 12 September 2022
, 1 year agono edit summary
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
No edit summary |
||
Line 649:
In string occur 23 consonants
</pre>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">include "NSLog.incl"
void local fn StringGetVowelAndConsonentCount( string as CFStringRef, vowels as ^long, consonents as ^long )
CFCharacterSetRef vowelSet = fn CharacterSetWithCharactersInString( @"aeiou" )
CFMutableCharacterSetRef consonentSet = fn MutableCharacterSetLetterSet
fn MutableCharacterSetRemoveCharactersInString( consonentSet, @"aeiou" )
*vowels = len( fn StringComponentsSeparatedByCharactersInSet( string, vowelSet ) ) - 1
*consonents = len( fn StringComponentsSeparatedByCharactersInSet( string, consonentSet ) ) - 1
end fn
void local fn DoIt
long index, vowels, consonents
CFArrayRef strings = @[@"abcdefghijklmnop345qrstuvwxyz",
@"The quick brown fox jumps over the lazy dog",
@"The answer my friend is blowing in the wind"]
for index = 0 to len(strings) - 1
fn StringGetVowelAndConsonentCount( strings[index], @vowels, @consonents )
NSLog(@"\"%@\" contains %ld vowels and %ld consonents",strings[index],vowels,consonents)
next
end fn
fn Doit
HandleEvents</syntaxhighlight>
{{out}}
<pre>
"abcdefghijklmnop345qrstuvwxyz" contains 5 vowels and 21 consonents
"The quick brown fox jumps over the lazy dog" contains 11 vowels and 24 consonents
"The answer my friend is blowing in the wind" contains 11 vowels and 24 consonents
</pre>
|