Tuesday, January 8, 2013

Charater count

# Gives a count of each character from t$
t$ = "Les Misérables, is a sung-through musical play based on the novel of the same name by French poet and playwright Victor Hugo. It has music by Claude-Michel Schönberg, original French lyrics by Alain Boublil and Jean-Marc Natel, with an English-language libretto by Herbert Kretzmer(...)"
t$ = lower(t$)
long= length (t$)
dim letters(255)

for n=1 to long
for x = 0 to 254
if chr(x)= mid(t$,n,1)then letters[x]=letters[x]+1
next x
next n

#Frequency table
for x = 0 to 254
if letters[x]>0 then print chr(x)+" "+letters[x]
next x

# Bar chart (onlny for plain letters)
bar = 0
for x = 97 to 125
if letters[x]>0 then
Text 0,bar*12,chr(x)
rect 13,bar*12+6,letters[x],8
end if
next x