Skip to main content

7.9.11 STRING_TO_CHARS

Function

Convert a string to an array of CHAR or BYTE

LD graphics

alt text

Parameter description

Interface VariableDeclarationData TypeDescription
SOURCE_STRINGInputSTRINGThe source string for the copy operation
POSInputDINTThe relative subscript position of the target array DEST_CHARS, starting from this position to copy characters
The POS parameter will be calculated from 0, corresponding to the starting subscript position of the array
DEST_CHARSInOutArray of CHAR
Array of BYTE
Destination array variable for copy operation
Copies characters into a structure of Array of (W)CHAR/ BYTE/ WORD data type
CNTOutputDINTActual number of characters moved
Function nameReturn valueINTError message
description
  • This instruction can copy the SOURCE_STRING string of data type STRING to the specified starting position of the DEST_CHARS array

  • In principle, the number of characters in the target field DEST_CHARS is at least the same as the number of characters copied from the source string SOURCE_STRING

  • If the destination field contains fewer characters than the source string, only up to the same number of characters as the destination field's maximum length will be written

  • Using the parameter POS, you can specify the starting position in the target field from which writing will be made. If the value of the POS parameter exceeds the limit of the DEST_CHARS array, it cannot be copied

  • Demonstration: If writing should start from the third position, use the value "2" in the parameter POS, the result of the following example CNT output will be equal to 6

Return value error code:

Error code*(W#16#)Description
0000No errors, complete copy successful
0001The truncation copy was successful, and the copied source length (the actual length of the string) exceeds the length allowed to be written to the array variable
8251The reference in the DEST_CHARS parameter is invalid and cannot be copied
8382The value of the POS parameter exceeds the limit of the DEST_CHARS array and cannot be copied

Example

  • LD sample animation is as follows:

alt text

  • ST example is shown in the following code:
OUT:=STRING_TO_CHARS(
SOURCE_STRING:=ARR,
POS:=IN2,
DEST_CHARS:=IN1,
CNT=>IN3
);