|
|
|
|
|
%stringPad()
Aliases | %stringPad( ) |
---|
Parameters | string @text, integer @width [, string @type [, string @padding [, string @paddingRight]]] |
---|
|
Applies padding to the given @text so that the return value is exactly @width characters wide. By default a single space is used as the padding string and the padding is applied to the right of the target text. To facilitate more complex types of padding the function accepts an optional @type paramater that can be set to one of the following:
padLeft - Apply padding to the left of the target.
padRight - Apply padding to the right of the target (default).
padBoth - Apply padding to both sides of the target.
padOut - Apply padding to both sides of the target but in the case of left padding work from the end of the padding text towards the beginning and outwards from the target.
padMirror - Apply padding to both sides of the target but in the case of left padding reverse the padding string and work outwards from the target.
The optional @padding parameter can be used to set what text is used for padding. If the amount of padding exceeds the size of the padding text then the paddig text will repeat. This parameter applies to both sides when padding.
The optional @paddingRight parameter can be used to apply different padding when padding the right of the target than that used for padding the left.
Example:
@data->+ = %stringPad( ' foo ', 20 ) ' (default)' @data->+ = %stringPad( ' foo ', 20, padLeft ) ' (padLeft)' @data->+ = %stringPad( ' foo ', 20, padBoth ) ' (padBoth)' @data->+ = %stringPad( ' foo ', 20, padRight, '-' ) ' (padRight)' @data->+ = %stringPad( ' foo ', 20, padLeft, '-' ) ' (padLeft)' @data->+ = %stringPad( ' foo ', 20, padBoth, '-' ) ' (padBoth)' @data->+ = %stringPad( ' foo ', 20, padRight, '1234' ) ' (padRight)' @data->+ = %stringPad( ' foo ', 20, padLeft, '1234' ) ' (padLeft)' @data->+ = %stringPad( ' foo ', 20, padBoth, '1234' ) ' (padBoth)' @data->+ = %stringPad( ' foo ', 20, padOut, '1234' ) ' (padOut)' @data->+ = %stringPad( ' foo ', 20, padMirror, '1234' ) ' (padMirror)' @data->+ = %stringPad( ' foo ', 20, padOut, '-->', '<--' ) ' (padOut)'
%printValue( @data, Blobbie )
Output:
[data] => (array) ( [1] => (string)[ foo (default)] [2] => (string)[ foo (padLeft)] [3] => (string)[ foo (padBoth)] [4] => (string)[ foo --------------- (padRight)] [5] => (string)[--------------- foo (padLeft)] [6] => (string)[------- foo -------- (padBoth)] [7] => (string)[ foo 123412341234123 (padRight)] [8] => (string)[123412341234123 foo (padLeft)] [9] => (string)[1234123 foo 12341234 (padBoth)] [10] => (string)[2341234 foo 12341234 (padOut)] [11] => (string)[3214321 foo 12341234 (padMirror)] [12] => (string)[>-->--> foo <--<--<- (padOut)] ) |
|
|
|
|
|
|
|