HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)

3- 19
140 C$="Elephants" !Current length of C$ is 9, implicit definition
150 A$="Caterpillar" !Now the current length of A$ is 11
999 END
Substrings
Substring Operations. Substring operations are classified into two
types; references and assignments. Substring references are
specifications of a string of characters that are to be extracted from a
string variable. The value of the string with the substring reference is
never changed. Substring references can occur alone on the right hand
side of assignment statements, in PRINT and PACK statements, and as
arguments to some built-in string functions, for example, UPC$.
Execution of a statement which contains a substring assignment results
in a possible change to the value of the string variable. Substring
assignment can occur as the target of an assignment statement on the left
hand side, in INPUT, TINPUT, LENTER, and other input statements and in
the UNPACK statement.
Substring References. A substring reference is a user-specified string
of characters that begins at a character specified by an index for a
string variable and has a length. By definition, the index of the first
character in a string is one. The length of a substring determines the
index of the last character in the string. If the index of the
substring's last character in the string is greater than the actual
length of the string variable then spaces are added to the characters
referenced until a string of characters with the appropriate length is
built.
There are two methods for specifying the substring value to be
referenced. The first is specification of the start index alone. The
second is specification of the start index and either the index of the
last character or the length.
Start Index Only. Syntax
str_var
[
start
]
Parameters
str_var
A valid string variable name or string variable array
element reference.
Start
A numeric literal or expression that evaluates to a
value between 1 and LEN(
str_var
)+1, inclusive.
Example
Consider the following substring reference:
10 PRINT A$[Start]
The statement references the substring starting at the character at in-