REPLACE block
Short summary
Name |
|
→POU type |
|
Category |
|
Conform to →IEC-standard |
currently restricted
|
Graphical interface |
|
Available since |
version 1.31.0 (for Neuron Power Engineer) |
Functionality
The block replaces a part of a string by another string and returns the newly created string.
At input IN1
, enter a string (= 1st string). At input IN2
, enter another string (= 2nd string). At input L
, enter the number of characters to replace (= the length of the part to delete). At input P
, enter the position within the 1st string. The block begins at this position to delete the characters and to insert the 2nd string instead of the deleted characters.
Special cases (see under "Example for usage within ST-editor"):
-
In case of
L = 0
, the block does not delete any characters in the 1st string. The 2nd string value is inserted at the positionP
. In this case, the outputENO
is set to valueTRUE
. -
If a negative value is connected to
L
, the corresponding characters before the positionP
are deleted in the string. In this case, the outputENO
is set to valueFALSE
. If the block would delete characters outside of the visible range (in front of position 1), the block does not delete and insert any characters. -
If the value
0
or a negative value is connected toP
, the block does not delete and insert any characters. In this case, the outputENO
is set to valueFALSE
as well. -
If the value for
L
and/orP
is > the length of the string forIN1
, the block does not delete any characters or just the characters that are within the visible range. In case ofP
> length of the string, the newly created string is filled with blanks until before the positionP
, the 2nd string is inserted beginning withP
. In this case, the outputENO
is set to valueFALSE
as well.
Neuron Power Engineer determines the character positions within a string as follows: 1
, 2
, ..., n. 1
corresponds to the leftmost character position and n
to the length of the string.
Three-character combination of the dollar sign ($
) followed by two hexadecimal digits are evaluated as single character. Example: The string '$B15
' (corresponds to '±5
') consists of 2 characters. See →character string literal for more examples for those combinations.
Inputs, return value
|
Identifier |
Description |
|
---|---|---|---|
Inputs: |
|
|
1st input value (= string where to replace) |
|
|
2nd input value (= string to insert) |
|
|
|
number of characters to replace |
|
|
|
start position in the 1st input value |
|
Return value: |
– |
|
|
Input EN
and output ENO
are available when →calling the block. See "Execution control: EN, ENO" for information on input EN
and output ENO
.
See:
-
"Blocks for safe logic" whether this block is supported for developing safety-relevant applications.
-
"Highlighting safe logic in the FBD-editor" for the effects when using the block as a block for safe logic.
Internal error diagnostic for block
The block checks the would-be return value.
If the return value cannot be mapped in the available memory (the return value is too large), the output ENO
of the block is set to value FALSE
(or an equivalent). When you are using nested blocks with STRING
values, observe that the memory for STRING
values is restricted (see "In case of nested string blocks: How can the return value be entirely mapped ?" for details and examples).
The following special case might occur regarding this error case: If the result of the call is assigned to a variable that is used as input parameter for the call of this block as well (see the following example), the output ENO
of the embracing →POU is set to value FALSE
for this error case (but not the output ENO
of the called block). Example: ResultString := REPLACE(IN1 := 'abc', IN2 := ResultString, L := 2, P := 1);
Moreover, the block checks the connected values whether a non-existent character position in a string is accessed. This is the case, if the value for L
or P
is > the length of the string for IN1
, a negative value is connected to L
or P
or the value 0
is connected to P
. The output ENO
of the block is set to value FALSE
(or an equivalent) in all these cases.
Example for usage within ST-editor
|
When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.