Count how many vowels and consonants occur in a string: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Cowgol) |
Alpha bravo (talk | contribs) (Added AutoHotkey) |
||
Line 141: | Line 141: | ||
5 vowels and 9 consonants (total) |
5 vowels and 9 consonants (total) |
||
</pre> |
</pre> |
||
=={{header|AutoHotkey}}== |
|||
<lang AutoHotkey>str := "Now is the time for all good men to come to the aid of their country." |
|||
oV:= [], oC := [], v := c := o := 0 |
|||
for i, ch in StrSplit(str) |
|||
if (ch ~= "i)[AEIOU]") |
|||
v++, oV[ch] := (oV[ch]?oV[ch]:0) + 1 |
|||
else if (ch ~= "i)[A-Z]") |
|||
c++, oC[ch] := (oC[ch]?oC[ch]:0) + 1 |
|||
else |
|||
o++ |
|||
Vowels := "{" |
|||
for ch, count in oV |
|||
Vowels .= """" ch """:" count ", " |
|||
Vowels := Trim(Vowels , ", ") "}" |
|||
Consonants := "{" |
|||
for ch, count in oC |
|||
Consonants .= """" ch """:" count ", " |
|||
Consonants := Trim(Consonants , ", ") "}" |
|||
MsgBox % result := str "`n`n" v+c+o " characters, " v " vowels, " c " consonants and " o " other" |
|||
. "`n" Vowels "`n" Consonants</lang> |
|||
{{out}} |
|||
<pre>Now is the time for all good men to come to the aid of their country. |
|||
69 characters, 22 vowels, 31 consonants and 16 other |
|||
{"a":2, "e":6, "i":4, "o":9, "u":1} |
|||
{"c":2, "d":2, "f":2, "g":1, "h":3, "l":2, "m":3, "N":3, "r":3, "s":1, "t":7, "w":1, "y":1}</pre> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<lang AWK> |
<lang AWK> |