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

Content added Content deleted
m (add REXX)
(Added XPL0 example.)
Line 250: Line 250:
contains (total) 22 vowels and 31 consonants.
contains (total) 22 vowels and 31 consonants.
contains (distinct) 5 vowels and 13 consonants.
contains (distinct) 5 vowels and 13 consonants.
</pre>

=={{header|XPL0}}==
<lang XPL0>string 0; \use zero-terminates strings
int VTC, VDC, \vowel total count, vowel distinct count
CTC, CDC, \consonant total count, consonant distinct count
VSet, CSet, \vowel and consonant bit arrays
Char, Item, I, J;
char Str;
[Str:= ["Forever XPL0 programming language.",
"Now is the time for all good men to come to the aid of their country."];
for J:= 0 to 1 do
[I:= 0; VTC:= 0; VDC:= 0; CTC:= 0; CDC:= 0; VSet:= 0; CSet:= 0;
while Str(J,I) do
[Char:= Str(J,I); I:= I+1;
if Char>=^A & Char<=^Z then
Char:= Char - ^A + ^a; \to lower case
if Char>=^a & Char<=^z then
[Item:= 1 << (Char-^a); \item in character set [a..z]
case Char of
^a, ^e, ^i, ^o, ^u:
[VTC:= VTC+1; \vowel
if (Item & VSet) = 0 then VDC:= VDC+1;
VSet:= VSet ! Item;
]
other [CTC:= CTC+1; \consonant
if (Item & CSet) = 0 then CDC:= CDC+1;
CSet:= CSet ! Item;
];
];
];
Text(0, @Str(J,0)); CrLf(0);
Text(0, "Contains "); IntOut(0, VTC); Text(0, " total vowels and ");
IntOut(0, CTC); Text(0, " consonants.^M^J");
Text(0, "Contains "); IntOut(0, VDC); Text(0, " distinct vowels and ");
IntOut(0, CDC); Text(0, " consonants.^M^J");
CrLf(0);
];
]</lang>

{{out}}
<pre>
Forever XPL0 programming language.
Contains 10 total vowels and 19 consonants.
Contains 5 distinct vowels and 9 consonants.

Now is the time for all good men to come to the aid of their country.
Contains 22 total vowels and 31 consonants.
Contains 5 distinct vowels and 13 consonants.
</pre>
</pre>