binary-search-treebubble-sortqbasic

Understanding the steps in making a counter for each letter when a sentence is inputed


I have an example of a program that shows how to set up a counter for how many times each letter of the alphabet was used. I don't understand the syntax of the middle portion of the program.

LET letter$ = MID$(sentence$, LETTERNUMBER, 1)

I have tried searching on youtube and tutorials online

CLS
REM Make Counters for each Letter!!!
DIM Count(ASC("A") TO ASC("Z"))
REM Get the Sentence
INPUT "Enter Sentence:", sentence$
LET sentence$ = UCASE$(sentence$)
FOR I = ASC("A") TO ASC("Z")
    LET Count(I) = 0
NEXT I

FOR LETTERNUMBER = 1 TO LEN(sentence$)
    LET letter$ = MID$(sentence$, LETTERNUMBER, 1)
    IF (letter$ >= "A") AND (letter$ <= "Z") THEN
        LET k = ASC(letter$)
        LET Count(k) = Count(k) + 1
    END IF
NEXT LETTERNUMBER
PRINT

REM Display These Counts Now
LET letterShown = 0
FOR letternum = ASC("A") TO ASC("Z")
    LET letter$ = CHR$(letternum)
    IF Count(letternum) > 0 THEN
        PRINT USING "\\##   "; letter$; Count(letternum);
    END IF
    LET letterShown = letterShown + 1
    IF letterShown = 7 THEN
        PRINT
        LET letterShown = 0
    END IF
NEXT letternum
END

A through Z appears with the count of how many times they appeared.


Solution

  • The MID$ function returns a portion of a STRING's value from any position inside a string.

    Syntax:

        MID$(stringvalue$, startposition%[, bytes%]) 
    

    Parameters: