strLib.copyStr
The system function strLib.copyStr copies one substring to another.
- target
- String from which a target substring is derived. Can be an item or a literal.
- targetSubstringIndex
- Identifies the starting byte in target, given that the first byte in target has the value 1. This index can be an integer literal. Alternatively, this index can be an item defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
- targetSubstringLength
- Identifies the number of bytes in the substring that is derived from target. The length can be an integer literal. Alternatively, the length can be an item defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
- source
- String from which a source substring is derived. Can be an item or a literal.
- sourceSubstringIndex
- Identifies the starting byte of the substring in source, given that the first byte in source has the value 1. This index can be an integer literal. Alternatively, this index can be an item defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
- sourceSubstringLength
- Identifies the number of bytes in the substring that is derived from source. The length can be an integer literal. Alternatively, the length can be an item defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
If the source is longer than the target, the source is truncated. If the source is shorter than the target, the source value is padded on the right with spaces.
Definition considerations
The following values are returned in sysVar.errorCode:
- 8
- Index less than 1 or greater than string length.
- 12
- Length less than 1.
- 20
- Invalid double-byte index. Index for a DBCHAR or UNICODE string points to middle of double-byte character.
- 24
- Invalid double-byte length. Length in bytes for a DBCS or UNICODE string is odd (double-byte lengths must always be even).
Example
target = "120056"; source = "34"; strLib.copyStr(target,3,2,source,1,2); // target = "123456"
Related reference
String handling (system words)