Function frequency: Difference between revisions

Added FreeBASIC
(→‎{{header|RPL}}: improved parsing)
(Added FreeBASIC)
 
Line 926:
$
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">Dim As String code, word, char
Dim As Integer i, j
Dim As String words()
Dim As Integer counts()
 
Open "i:\your_file.bas" For Input As #1
While Not Eof(1)
Line Input #1, code
For i = 1 To Len(code)
char = Lcase(Mid(code, i, 1))
If char >= "a" And char <= "z" Then
word &= Mid(code, i, 1)
Elseif word <> "" Then
For j = 0 To Ubound(words)
If words(j) = word Then
counts(j) += 1
Exit For
End If
Next
If j > Ubound(words) Then
Redim Preserve words(Ubound(words) + 1)
Redim Preserve counts(Ubound(counts) + 1)
words(Ubound(words)) = word
counts(Ubound(counts)) = 1
End If
word = ""
End If
Next
Wend
Close #1
 
For i = 0 To 9
Dim As Integer maxj = 0
For j = 0 To Ubound(counts)
If counts(j) > counts(maxj) Then maxj = j
Next
Print words(maxj); " occurs"; counts(maxj); " times"
counts(maxj) = 0
Next
 
Sleep</syntaxhighlight>
 
=={{header|Go}}==
2,130

edits