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

Content added Content deleted
(Added AutoHotkey)
(→‎{{header|Ring}}: simplified, removed unnecessary library dependency and chance of mis-tabulation of characters after "Z" and before "a")
Line 1,635: Line 1,635:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<lang ring>? "working..."
load "stdlib.ring"
see "working..." + nl
str = '"' + "Forever Ring Programming Language" + '"'
str = '"' + "Forever Ring Programming Language" + '"'
vowel = 0 vowels = [] for x in "AEIOUaeiou" add(vowels, x) next
vowel = 0
ltrc = 0 all = 'A':'z' while all[27] != 'a' del(all, 27) end
cons =0


for n = 1 to len(str)
for n in str
if find(vowels, n) > 0 vowel++ ok
strc = str[n]
if isvowel(str[n]) = 1
if find(all, n) > 0 ltrc++ ok
vowel += 1
ok
if isconsonant(strc)
cons += 1
ok
next
next


see "Input string = " + str + nl
? "Input string = " + str
see "In string occur " + vowel + " vowels" + nl
? "In string occur " + vowel + " vowels"
see "In string occur " + cons + " consonants" + nl
? "In string occur " + (ltrc - vowel) + " consonants"
see "done..." + nl
put "done..."</lang>

func isconsonant(c)
bool1 = not isvowel(c)
bool2 = (ascii(c) > 64 and ascii(c) < 91)
bool3 = (ascii(c) > 96 and ascii(c) < 123)
if bool1 and (bool2 or bool3)
return 1
else
return 0
ok
</lang>
{{out}}
{{out}}
<pre>
<pre>working...
working...
Input string = "Forever Ring Programming Language"
Input string = "Forever Ring Programming Language"
In string occur 11 vowels
In string occur 11 vowels
In string occur 19 consonants
In string occur 19 consonants
done...
done...</pre>
</pre>


=={{header|Ruby}}==
=={{header|Ruby}}==