RosettaCodeData/Task/Letter-frequency/M2000-Interpreter/letter-frequency.m2000
2026-04-30 12:34:36 -04:00

24 lines
657 B
Text

document file1$={Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation), but some only count letters A to Z
}
const Ansi=3, nl$=chr$(13)+chr$(10), Console=-2
save.doc file1$, "checkdoc.txt", Ansi
open "checkdoc.txt" for input as F
buffer onechar as byte
m=0
dim m(65 to 90)
while not eof(#F)
get #F, onechar
a$=chr$(eval(onechar,0))
if a$ ~ "[A-Za-z]" then
m++
m(asc(ucase$(a$)))++
end if
end while
close #F
document Export$
for i=65 to 90
if m(i)>0 then Export$=format$("{0} - {1:2:4}%",chr$(i),m(i)/m*100)+nl$
next
print #Console, Export$
clipboard Export$