The CENTER command file is an example of string manipulation functions. It centers a supplied string and displays it on $STDLIST, usually the user's terminal screen.
A character string is entered as parameter data when the command file is invoked. The variable CENT_SPC is defined as a string variable of 40 blank spaces. A portion of this string of blanks is inserted on the left side of the original text string to center it. The expression determines the number of blanks to be entered and adds them to the character string before echoing the phrase. Note that parameters must always use explicit dereferencing.
Figure 7-1 Center Command File
PARM STRING
SETVAR CENT_SPC " "
ECHO ![LFT(CENT_SPC,(80-LEN("!STRING"))/2)]!STRING
DELETEVAR CENT_SPC
COMMENT ** END OF CENTER **
|
The repeat function can also be used to simplify this routine.
Figure 7-2 Center Command File with the Repeat Function
PARM STRING
ECHO ![RPT(" ",(80-LEN("!STRING"))/2)]"!STRING"
COMMENT ** END OF CENTER **
|