Returns the length of a string in ASCII characters. The count includes all characters in the string, starting at 1 for the first character.
Examples
PRINT LEN("Retro Rocket")
Produces 12.
REM Length of an empty string
PRINT LEN("")
Produces 0.
REM Use LEN to iterate over characters
name$ = "HELLO"
FOR i = 1 TO LEN(name$)
PRINT MID$(name$, i - 1, 1)
NEXT
REM Truncate a string if too long
line$ = "This is a long string"
IF LEN(line$) > 10 THEN
PRINT "Truncated: "; LEFT$(line$, 10)
ENDIF
Notes
- Returns an integer value ≥ 0.
- Length is measured in characters, not bytes — since Retro Rocket BASIC strings are ASCII, the two are identical.
- Useful together with LEFT$, RIGHT$, and MID$ for string slicing.
See also: LEFT$ · RIGHT$ · MID$ · ASC