RosettaCodeData/Task/Letter-frequency/M2000-Interpreter/letter-frequency.m2000

25 lines
657 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
document file1$={Open a text file and count the occurrences of each letter.
2026-04-30 12:34:36 -04:00
Some of these programs count all characters (including punctuation), but some only count letters A to Z
}
2023-07-01 11:58:00 -04:00
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)
2026-04-30 12:34:36 -04:00
get #F, onechar
a$=chr$(eval(onechar,0))
if a$ ~ "[A-Za-z]" then
m++
m(asc(ucase$(a$)))++
end if
2023-07-01 11:58:00 -04:00
end while
close #F
document Export$
for i=65 to 90
2026-04-30 12:34:36 -04:00
if m(i)>0 then Export$=format$("{0} - {1:2:4}%",chr$(i),m(i)/m*100)+nl$
2023-07-01 11:58:00 -04:00
next
print #Console, Export$
clipboard Export$