Documentation Comments
Use this form to comment on this topic. You can also provide any general observations about the Online Documentation, or request that additional information be added in a future release.
Reality V15.0 ()
FOLD Function (DataBasic) (m618703+fold_f.htm)
Places delimiters in a string in place of spaces, so as to break the string into lines with a specified maximum length.
FOLD(string[, foldWidth|, delimiter])
string The text to fold.
foldWidth The maximum number of characters in each fold. If omitted, defaults to 25.
If a dynamic array of integers is specified, the values of the elements are used in order as fold widths, with the last value being used for any folds that remain. Note that if an element that does not evaluate to an integer is encountered, a null string is returned.
Note that array elements are only used if the delimiter parameter is included. If foldWidth is an array, but no delimiter is specified, the first element in the array is used for all folds.
delimiter A string that specifies the delimiter to be inserted into the folded string:
Note: You must supply either foldWidth or delimiter or both; if both are omitted the code will not compile.
A string containing the processed text.
The FOLD function counts the characters in the string and replaces the last space before the position specified by foldWidth with the specified delimiter. If there are no spaces before the specified position, a delimiter is inserted after the character in the position specified by foldWidth. The character following the delimiter is then taken as the start of a new string and the process repeats until the end of the string.
This function provides similar functionality to the T alignment code in a data definition item.
The following program breaks a line of text into attributes, and displays them on the screen:
LINE = "" FOR I = 1 TO 4 LINE := "The quick brown fox jumps over the lazy dog. " NEXT I LINE := "Thequickbrownfoxjumpsoverthelazydog." LINES = FOLD(LINE, 23) FOR I = 1 TO DCOUNT(LINES, @AM) PRINT LINES<I> NEXT I
The output from this program:
The quick brown fox
jumps over the lazy
dog. The quick brown
fox jumps over the lazy
dog. The quick brown
fox jumps over the lazy
dog. The quick brown
fox jumps over the lazy
dog.
Thequickbrownfoxjumpsov
erthelazydog.