omron — PACK program instruction

PACK program instruction Details This instruction replaces a substring within an array of strings or within a string variable. When an array of strings is being modified, the substring is permitted to overlap two elements of the string array. For example, a 10-character substring whose first character is to replace the 127th character in element [3] supersedes the last two characters in element [3] and the first eight characters of element [4]. If the array element to be modified is not defined, the element is created and filled with ASCII NUL characters (^H00) up to the specified start of the substring.

Similarly, if the array element to be modified is too short, the string is padded with ASCII NUL characters to the start of the substring. In order to efficiently access the string array, this function assumes that all of the array elements, from the start of the array until the element before the element accessed, are defined and are 128 characters long. For multidimensional arrays, only the right-most array index is incremented to locate the substring. Thus, for example, element [2,3] is followed by element [2,4]. When a string variable is modified, the replacement is done in a manner similar to that for an individual array element.

However, an error results if the operation causes the string to be longer than 128 characters. Example The instruction below replaces 11 characters within the string array $list[ ]. The replacement is specified as starting in array element $list[3]. However, since the first character replaced is to be number 130, the 11-character substring actually replaces the second through 12th characters of $list[4]. PACK $list[3], 130, 11 = $string Related Keywords $MID string function $UNPACK string function eV+Language Reference Guide, v2.x, 18319-000 Rev A Page 382