basic.substring.assignment Definition/BASIC Program

basic.substring.assignment

Command basic.substring.assignment Definition/BASIC Program
Applicable release versions: AP
Category BASIC Program (486)
Description allows assigning a substring to a variable

"beg.pos.expression" indicates the starting position in the expression.

If "beg.pos.expression" is 0, the expression is inserted at the beginning of the target string.

If "beg.pos.expression" is less than 0, blanks are inserted between the expression and the string for a length equal to the absolute value of "beg.pos.expression".

If "beg.pos.expression" is greater than the length of the string, blanks are appended to the end of the string to account for the value of "beg.pos.expression" prior to the expression being added to the result.

"len.expression" is the number of characters to overlay within the string expression.

If "len.expression" is 0, the expression is inserted prior to the starting character position within the string.

If "len.expression" is less than 0, then "len.expression" defaults to 0.

If "len.expression" is greater than 0, the corresponding number of characters in the string are overlayed.

If "len.expression" is greater than the number of characters in the string, starting from the starting position count, then "len.expression" defaults to the number of characters within the string, minus the starting position count.

If the length of the "substring.expression" to overlay is greater than the "len.expression", the additional characters are included in the resulting expression. Only the number of characters specified in "len.expression" are overlayed. The additional characters are inserted prior to the next position in the original expression.
Syntax variable[beg.pos.expression, len.expression] = expression
Options
Example
string = "xbcd"
string[1,1] = "a"

This assigns the letter "a" to the first character of the 
"string" variable. After assigning, "string" contains 
"abcd".

string = 'abcd'
string[2,2] = 'xxx'

This results in the string, 'axxxd'. Notice that the additional 
characters beyond the length of the overlay are inserted. On previous versions 
(before AP), the result of these statements would produce the string, 
'axxd'.

The following program tests various combinations of substring replace.

string = "abcdef"
s = string ; s[ 0 , 0]= "xx"; crt s
s = string ; s[ 0 , 1]= "xx"; crt s
s = string ; s[ 1 , 1]= "xx"; crt s
s = string ; s[-1 , 0]= "xx"; crt s
s = string ; s[-1 , 1]= "xx"; crt s
s = string ; s[-1 ,-1]= "xx"; crt s
s = string ; s[ 7 , 0]= "xx"; crt s
s = string ; s[ 7 , 1]= "xx"; crt s
s = string ; s[ 7 ,-1]= "xx"; crt s
s = string ; s[ 8 , 1]= "xx"; crt s

The output of this program is as follows:

xxabcdef
xxbcdef
xxbcdef
xx abcdef
xx bcdef
xx abcdef
abcdefxx
abcdefxx
abcdefxx
abcdef xx

The following program creates "waves" of output:

string="#####"; s=string
for x=-3 to 7
  for j=-3 to 7
    s[x,j]='..'
    crt s
  next j
next x
end
Purpose
Related basic.substring.expressions
basic.substring.field.store
basic.field
basic.casing
basic.substring.extraction
basic.assignment
basic.[