STR_PAD
Use the STR_PAD script function to extend a string to a certain length. Do so by adding a specified number of characters on the right, on the left, or on both sides of this string.
Syntax
STR_PAD (String, [Character], Total length, Alignment)
Parameters
-
STR_PAD
Extends a string to a certain length - String
The string that should be extended.
Format: script literal or script variable - Character
(Optional) Any character that should be used to extend the string
Format: AE name, script literal or script variable
Default value: a blank (" ") - Total length
The final length that the string should have.
Format: any number that you specify without quotation marks, a script literal, or a script variable - Alignment
Defines where the original string is positioned
Allowed values:- LEFT
The string is positioned on the left, and the additional characters on the right. - RIGHT
The string is positioned on the right, and the additional characters on the left. - CENTER
The string is positioned centrally and the additional characters are equally distributed on the left and right side of the string. If the number of characters to be added is not even, the position on the right side of the string includes one character more.
- LEFT
Return code: the extended string
Examples
The following example shows three ways of extending a string that has 20 characters to a final length of 31 characters. The result is shown in the activation report.
:SET &STRING# = "String for Scripting"
:SET &STRLEN# = 31
:SET &STRNEW# = STR_PAD(&STRING#, ".", &STRLEN#, "LEFT")
:PRINT &STRNEW#
:SET &STRNEW# = STR_PAD(&STRING#, "+", &STRLEN#, "CENTER")
:PRINT &STRNEW#
:SET &STRNEW# = STR_PAD(&STRING#, "_", &STRLEN#, "RIGHT")
:PRINT &STRNEW#
The following result is written to the activation report:
String for Scripting...........
+++++String for Scripting++++++
___________String for Scripting
See also: