40
CipherLab BASIC Programming Part I
4.4.3 GETTING THE LENGTH OF A STRING
LEN
Purpose To return the length of a string.
Syntax A% = LEN(X$)
Remarks “A%” is an integer variable to be assigned to the result.
“X$” may be a string variable, string expression, or string constant.
Note that non-printing characters and blanks are counted.
Example
String1$ = “abcde ”
‘A% = 6, including the blank
4.4.4 SEARCHING FOR STRINGS
Searching for a string inside another one is one of the most common string-processing
tasks. INSTR is provided for this task.
INSTR
Purpose To search if one string exists inside another one.
Syntax A% = INSTR([N%,] X$, Y$)
Remarks “A%” is an integer variable to be assigned to the result.
“N%” is a numeric expression in the range of 1 to 255. Optional offset N
the position for starting the search.
“X$”, “Y$” may be a string variable, string expression, or string constant.
If Y$ is found in X$, INSTR returns the position of the first occurrence of Y$
in X$, from the starting point.
If N is larger than the length of X$ or if X$ is null, of if Y$
INSTR returns 0.
If Y$ is null, INSTR returns N (or 1 if N is not specified).
Example
String1$ = “11025John Thomas, Accounting Manager”
String2$ = “,”
EmployeeName$ = MID$(String1$, 6, INSTR(String1$, String2$) – 6)
‘ the employee’s name starts at the sixth character