了解输入句子时为每个字母制作计数器的步骤

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

我有一个程序示例,展示了如何设置一个计数器,计算每个字母被使用的次数。我不明白程序中间部分的语法。

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

我试过在 youtube 和在线教程上搜索

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 到 Z 并显示它们出现的次数。

MID$ 函数return是字符串中任意位置的字符串值的一部分。

语法:

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

参数:

  • 字符串值$

    可以是任何具有长度的文字或变量字符串值。参见 LEN。

  • 起始位置%

    指定第一个字符的non-zero位置return由函数编辑。

  • 字节%

    (可选)告诉函数 return 有多少个字符,包括使用时的第一个字符。

另一种计算字符串中字符的方法:

REM counts and displays characters in a string
DIM count(255) AS INTEGER
PRINT "Enter string";: INPUT s$
' parse string
FOR s = 1 TO LEN(s$)
    x = ASC(MID$(s$, s, 1))
    count(x) = count(x) + 1
NEXT
' display string values
FOR s = 1 TO 255
    PRINT s; "="; count(s); " ";
    IF (s MOD 8) = 0 THEN
        PRINT
        IF (s MOD 20) = 0 THEN
            PRINT "Press key:";
            WHILE INKEY$ = "": WEND: PRINT
        END IF
    END IF
NEXT
END