Example 1
In the following example, six characters (set by CNT = UDINT#6) of the input string 'MyTextString' are copied to the array variable My_Int_Array (INT array with a total length of 10). Copying the first character of the input string starts at array index [2] (BUF_OFF = 2 x SIZEOF(INT) = 4).
Data type declaration:
TYPE
MyArray : ARRAY[0..10] OF INT;
END_TYPE
'Variables' table with declarations:
Code in ST:
/* STRING_COPY(IN:STRING, BUFFER:ANY, BUF_OFF:ANY_INT, CNT:ANY_INT) */
Out := STRING_COPY(MyString, My_Int_Array, UDINT#4, UDINT#6);
Result (values shown in WATCHES window):
Example 2
In the following example, four characters (set by CNT = UDINT#4) of the input string 'MyTextString' are copied to the array variable My_Byte_Arrray (Byte array with a total length of 10). Copying the first character 'M' (=16#4D) of the input string starts at array index [3] (BUF_OFF = 3 x SIZEOF(BYTE) = 3). The second character 'y' (=16#79) is copied to the second byte and so on.
Data type declaration:
TYPE
MyArray1 : ARRAY[0..10] OF BYTE;
END_TYPE
'Variables' table with declarations:
Code in ST:
/* STRING_COPY(IN:STRING, BUFFER:ANY, BUF_OFF:ANY_INT, CNT:ANY_INT) */
Out := STRING_COPY(MyString, My_Byte_Array, UDINT#3, UDINT#4);
Result (values shown in WATCHES window):