Insert String (INSERT)
Use the INSERT instruction to add ASCII characters to a specified location within a
string.
Available Languages
Ladder Diagram

Function Block
Structured Text
INSERT (SourceA,SourceB,Start,Dest);
Operands
There are data conversion rules for mixed data types within an instruction. See Data conversions. The INSERT instruction uses the following operands.
Ladder Diagram and Structured Text
Operand | Type | Format | Description | Notes |
|---|---|---|---|---|
Source A | String type | Tag | String to add the characters to | String types are default STRING data types or any new string types you create |
Source B | String type | Tag | String containing the characters to add | |
Start | SINT DINT INT | Immediate tag | Position in Source A to add the characters | Enter a number between 1 and the DATA size of the Source. |
Destination | String type | Tag | String to store the result |
See Structured Text Syntax for
more information on the syntax of expressions within structured text.
Description
The INSERT instruction adds the characters in Source B to a designated position within Source A and places the result in the Destination.
- Start defines where in Source A that Source B is added.
- Unless Source A and the Destination are the same tag, Source A remains unchanged.
Affects Math Status Flags
No
Fault conditions
Type | Code | Cause | Recovery Method |
|---|---|---|---|
4 | 51 | The LEN value of the string tag is greater than the DATA size of the string tag. |
|
4 | 52 | The output string is larger than the destination. | Create a new string type that is large enough for the output string. Use the
new string type as the data type for the destination. |
4 | 56 | The Start or Quantity value is invalid. | Check that the Start value is between 1 and the DATA size of the Source. |
Execution
Ladder Diagram
Condition | Ladder Diagram Action |
|---|---|
Prescan | The rung-condition-out is set to false. |
Rung-condition-in is false | The rung-condition-out is set to false. |
Rung-condition-in is true | The instruction executes.
The rung-condition-out is set to true. |
Postscan | The rung-condition-out is set to false. |
Execution
Structured Text
Condition | Action |
|---|---|
Prescan | See Prescan in the Ladder Diagram table |
Normal execution | See rung-condition-in is true in the Ladder Diagram table. |
Postscan | See Postscan in the Ladder Diagram table |
Example
When
temp_high
is set, the INSERT instruction adds the characters in string_2
to position 2 within string_1
and places the result in string_3
.Ladder Diagram

Structured Text
IF temp_high THEN
INSERT(string_1,string_2,2,string_3);
temp_high := 0;
END_IF;
Provide Feedback