Script Function: Extends a string to a certain length.
STR_PAD(String, [Character], Total Length, Position)
Syntax |
Description/Format |
---|---|
String |
The string that should be extended. |
Character |
Any character that will be used to extend the string. Default value: " " |
Total Length | The length to which the string should be extended. Format: a number without inverted commas, script literal or script variable |
Position |
The string's position. Allowed values: |
Return codes |
---|
The extended string. |
This script function extends a string to a certain length. You specify the character that should be used for the extension in the parameter Character. By default, blanks are used.
You can also define the order in which the string should be shown in the result (parameter Position). The possible values are left, right and center.
Center means that the required characters will be equally positioned to the left and to the right of the string. If the number of characters that are required to extend the string is not even, the position to the right of the string will include one character more than the position to the string's left.
The following example increases one and the same string in three different ways and writes the result to the activation protocol.
:SET &STRING# = "UC4 String"
:SET &STRLEN# = 15
: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 protocol:
UC4 String.....
UC4 String
_____UC4 String
See also:
Script element | Description |
---|---|
STR_SPLIT | Splits a string to several parts using a separator. |
Script Elements - Activation Data
About Scripts
Script Elements - Alphabetical Listing
Script Elements - Ordered by Functions