Skip to content

Insert Command

Obsolete

This command is replaced by the Insert function.

See Also

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 insert to place blank spaces in a string, for centering, or for other purposes.
  • If position is greater than the length of destination, insert will append source to destination just as if you had used the append command.
  • If position is less than 2, insert will insert source at the beginning (left end) of destination.
  • If either source or destination is not of type String, it will be converted internally to a string for the insert operation.
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.