Letter frequency: Difference between revisions

Content added Content deleted
(Added Kotlin)
No edit summary
Line 1,063: Line 1,063:
Y : 1
Y : 1
Z : 1
Z : 1
</pre>

=={{header|Gambas}}==
Input:
<pre>
This is the one question that most people ask. Why bother learning a completely different computing environment, when the operating
system that ships with most desktops, laptops, and servers works just fine? To answer that question, I would pose another question.
Does that operating system you’re currently using really work “just fine”? Or are you constantly battling viruses, malware, slow
downs, crashes, costly repairs, and licensing fees?

If you struggle with the above, and want to free yourself from the constant fear of losing data or having to take your computer in
for the “yearly clean up,” Linux might be the perfect platform for you. Linux has evolved into one of the most reliable computer
ecosystems on the planet. Combine that reliability with zero cost of entry and you have the perfect solution for a desktop platform.
</pre>
<lang gambas>Public Sub Form_Open()
Dim sData As String = File.Load("data.txt")
Dim iCount, iSpaces, iLetters, iOther As Integer
Dim bPunctuation As Boolean

For iCount = 1 To Len(sData)
If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", UCase(Mid(sData, iCount, 1))) Then
Inc iLetters
bPunctuation = True
End If
If Mid(sData, icount, 1) = " " Then
Inc iSpaces
bPunctuation = True
End If
If bPunctuation = False Then Inc iOther
bPunctuation = False
Next

Message("Text contains " & Len(sData) & " characters\n" & iLetters & " Letters\n" & iSpaces & " Spaces\n" & iOther & " Punctuation, newlines etc.")

End</lang>
Output:
<pre>
Text contains 849 characters
677 Letters
135 Spaces
42 Punctuation, newlines etc.
</pre>
</pre>