Working with substrings
You can use brackets to treat a CHAR(n) or STRING variable as an array of characters.
The following tips and tricks make use of this idea.
Creating a substring
Tip:
The following example shows how to use the bracket
syntax to create a substring:
myStringVar1 STRING = "abcdefghijklmn";
myStringVar2 STRING;
myStringVar2 = myStringVar1[3:6];
writeStdOut(myStringVar2); // displays "cdef"Right-justifying a character variable
Tip:
The following example shows how to create a fixed
length character variable to hold the right-justified contents of
a STRING:
myCharVar CHAR(10);
myStringVar STRING = "abc";
myCharVar[10 - strLib.characterLen(myStringVar) : 10] = myStringVar;
writeStdOut(myCharVar); // displays " abc"