FOLD function
Syntax
FOLD (string, length )
CALL !FOLD (subdivided.string, string, length)
Description
Use the FOLD function to divide a string into a number of substrings separated by field marks.
string is separated into substrings of length less than or equal to length. string is separated on blanks, if possible, otherwise it is separated into substrings of the specified length.
subdivided.string contains the result of the FOLD operation.
If string evaluates to the null value, null is returned. If length is less than 1, an empty string is returned. If length is the null value, the FOLD function fails and the program terminates with a run-time error message.
Examples
PRINT FOLD("THIS IS A FOLDED STRING.",5)
This is the program output:
THISFIS AFFOLDEFDFSTRINFG.
In the following example, the blanks are taken as substring delimiters, and as no substring exceeds the specified length of six characters, the output would be:
RED FM ORANGEFM YELLOWFM GREENFMBLUEFMINDIGOFMVIOLET
The field mark replaces the space in the string:
A="RED ORANGE YELLOW GREEN BLUE INDIGO VIOLET"
CALL !FOLD (RESULT,A,6)
PRINT RESULT