Count how many vowels and consonants occur in a string: Difference between revisions
Content added Content deleted
m (→{{header|ALGOL 68}}: formatting...) |
Walterpachl (talk | contribs) m (add REXX) |
||
Line 137: | Line 137: | ||
<pre>5 vowels and 8 consonants occur in the string "Forever Ring Programming Language"</pre> |
<pre>5 vowels and 8 consonants occur in the string "Forever Ring Programming Language"</pre> |
||
=={{header|REXX}}== |
|||
<lang rexx>/* REXX */ |
|||
Parse Arg s |
|||
If s='' Then |
|||
s='Forever Wren programming language' |
|||
con='BCDFGHJKLMNPQRSTVWXYZ' |
|||
vow='AEIOU' |
|||
su=translate(s) /* translate to uppercase */ |
|||
suc=su |
|||
sx='' /* eliminate duplicate characters */ |
|||
Do While suc<>'' |
|||
Parse Var suc c +1 suc |
|||
If pos(c,sx)=0 Then sx=sx||c |
|||
End |
|||
Say s /* show input string */ |
|||
Call count su /* count all consonants and vowels */ |
|||
Call count sx,'distinct' /* count unique consonants and vowels */ |
|||
Exit |
|||
count: |
|||
Parse Arg s,tag |
|||
sc=translate(s,copies('+',length(con))copies(' ',256),con||xrange('00'x,'ff'x)) |
|||
sv=translate(s,copies('+',length(vow))copies(' ',256),vow||xrange('00'x,'ff'x)) |
|||
Say length(space(sc,0)) tag 'consonants,' length(space(sv,0)) tag 'vowels' |
|||
Return</lang> |
|||
{{out}} |
|||
<pre>Forever Wren programming language |
|||
19 consonants, 11 vowels |
|||
9 distinct consonants, 5 distinct vowels</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
<lang ring> |
<lang ring> |
||
load "stdlib.ring" |
load "stdlib.ring" |