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

3- 21
20 B$=A$[1] !Assigns "basic" to B$ - characters 1 to LEN(B$)
30 B$=A$[2,3] !Assigns "as" to B$ - characters 2,3
40 B$=A$[2;3] !Assigns "asi" to B$ - characters 2,3,4
50 B$=A$[4,7] !Assigns "ic " to B$ - characters 4,5 + 2 spaces
60 B$=A$[6;2] !Assigns " " to B$ - a null string + 2 spaces
70 B$=A$[7,10] !Range error because 7 > LEN(A$)+1
Substring Assignment. A substring assignment begins at a user-speci-
fied index corresponding to a character position in a string variable
and has a length. By definition, the index of the first character in a
string is one. The length of the substring determines the index of the
last character in the string to which a value is assigned. If the number
of characters assigned to the string is less than the length of the
substring specified, then spaces are assigned to the remaining charac-
ters in the string variable until the number of characters assigned is
equal to the length of the substring.
There are two methods for specifying the target substring. The first is
the specification of the starting index alone, and the second is
specification of the starting 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 assignment statement:
10 A$[Start]=B$
Execution of this statement assigns the value of B$ to A$ beginning at
character Start.
If Start= (LEN(A$)+1), then a string append is done.
If the LEN of the string following assignment is greater than that before
assignment, then the actual length of A$ is reset.
If (Start+LEN(B$)-1) <= MAXLEN(A$), then the value of B$ is assigned to
A$. Otherwise, (MAXLEN(A$)-Start+1) characters from the value of B$ are
assigned to A$.
Note that as long as 1 <= Start <= LEN(A$)+1, then regardless of the
length of B$, no bounds violation occurs during the string assignment.
Start Index and End Index or Length.