Insert Command
Obsolete
This command is replaced by the Insert function.
Purpose
To insert one string into another.
Syntax
insert
source
in
destination [
at
position
]
Argument Explanation
- source: May be of any class.
- destination: May not be a constant or an expression.
What It Does
The insert command places source inside destination at the character position in destination designated by the value of position. The value of the predefined variable strmark will be set to that of position.
string city
move "Niagara, NY" to city
insert " Falls" in city at 8
In this example, the string variable city is declared, and "Niagara, NY" is moved to it. The value of the predefined variable strmark is set to 8. The insert command changes the value of city to "Niagara Falls, NY" by inserting " Falls" at the 8th position in the original value of city. Note the space between the first quotation mark and the "F" in "Falls"; without it, the result would be "NiagaraFalls, NY".
If position is omitted from the command, the value of the predefined variable strmark will be used for the function. strmark is set by the preceding left, mid, pad, pos, and replace commands.
string city
move "Niagara, NY" to city
pos "," in city
insert " Falls" in city
This example yields the same results as the one above. The pos command moves the position (8) of the first comma in city to strmark. The following insert command, lacking an at position argument, inserts " Falls" at the position of the comma.
If the length of destination is set in the string command which established it to a length (###) shorter than the combined inserted length, then only the first ### characters of the combined inserted value remain in destination. No error is declared if this occurs.
Notes
- You can use
insertto place blank spaces in a string, for centering, or for other purposes. - If
positionis greater than the length ofdestination,insertwill appendsourcetodestinationjust as if you had used theappendcommand. - If
positionis less than 2,insertwill insertsourceat the beginning (left end) ofdestination. - If either
sourceordestinationis not of type String, it will be converted internally to a string for theinsertoperation.
number num
move 12 to num
insert 3 in num at 2
The result of this command would be a value of 132 in num.