Substring

1. A String variable can have a substring qualifier.
When s$ is a string variable, and m,n are numeric expressions, s$(m:n) stands for the substring of s$ from m-th character to n-th character.
For example, if a$="12345", a$(2:4) is "234".


2. A string variable with a substring qualifier can be written on the left hand side of a LET statement.
Example.
LET s$(m:n)=a$
The substring of s$ from m-th character to n-th character is replaced with a$.
The length of a$ can be different from the length of the substring to be replaced.
Example.

10 LET A$="1234567"
20 LET A$(2:6)="ABC"
30 PRINT A$
40 END

Output

1ABC7



Insertion of a string to a string variable
LET A$(n+1:n)=b$
inserts b$ at the n-th character of A$.
Example.

10 LET A$="1234567"
20 LET LET A$(4:3)="ABC"
30 PRINT A$
40 END

Output 123ABC4567



Deletion of a substring from a string variable
LET A$(m:n)=""
deletes m-th character to n-th character from A$.
Example.

10 LET A$="1234567"
20 LET LET A$(4:6)=""
30 PRINT A$
40 END

Output 1237



(Note)
String variables with substring qualifiers can be written in a INPUT statement or a READ statement.

A substring qualifier can not be applied to a string expression.
A function that picks out a substring from a string can be defined as follows.
DEF SUBSTR$(a$,m,n)=a$(m:n)
SUBSTR$ is pre-defined on Decimal BASIC, so the DEF statement above need not be written.