setSubstr()

The vgLib.setSubstr() system function replaces each character in a substring with a specified character.

vgLib.setSubstr() is one of a number of functions maintained for compatibility with earlier versions. New code can use standard EGL operators for these purposes.

Syntax

  vgLib.setSubstr(
    target CharType inOut,
    targetSubstringIndex INT in,
    targetSubstringLength INT in,
    source CharType inOut)
target
The variable to be changed.
targetSubstringIndex
Identifies the starting byte of the substring in target, given that the index value of the first byte is 1. This index can be an integer literal or variable (INT or BIN(9)).
targetSubstringLength
Identifies the number of bytes in the substring that is derived from target. The length can be an integer literal or variable (INT or BIN(9)).
source
If the target variable is CHAR, MBCHAR, or HEX, the source variable must be a one-byte CHAR, MBCHAR, or HEX variable or a CHAR literal. If the target is a DBCHAR or UNICODE variable, the source must be a single-character DBCHAR or UNICODE variable.

Error considerations

If you use V6 exception compatibility (see Using V6 exception compatibility), the following values are returned in sysVar.errorCode:
8
Index is less than 1 or greater than the string length.
12
Length is less than 1.
20
Index for a DBCHAR or UNICODE string points to the middle of a double-byte character.
24
Length in bytes for a DBCHAR or UNICODE string is odd (double-byte lengths must always be even).

Example

The following example shows the vgLib.setSubstr() function:

target Char(15) = "abcdefghijklm"; // target is "abcdefghijklm  "
vgLib.setSubstr(target,2,5," "); // target is now "a     ghijklm  "

Feedback