Insane
/ /

XtScript Function: str_pad

Pad a string to a specified length from another string.

pad is an XtScript function that can padding additional string to the main string.

XtScript pad function basic syntax:

<!--parser:xtscript-->
	call str_pad $val=...; $pad_length=...; $pad_string=...; $pad_type=...
<!--/parser:xtscript-->

Available arguments in XtScript pad function:

ArgumentMandatoryValueExplanation
$pad_lengthRequiredNumberSpecified the maximum length of the resulted string after pad. If the value is smaller than the main string ($val), then the main string will not be pad.
$pad_stringOptionalString. space will be used as default value if this argument is not set.Specified the sting to be pad to the main string.
$pad_typeOptionalThe value can be one of following rules:
STR_PAD_RIGHT (default), pad the string to the right.
STR_PAD_LEFT, pad the string to the left.
STR_PAD_BOTH, pad the string both to the right and left.
Specified which position the main string ($val) will be pad.

Learn XtScript pad function from examples

Pad a string using XtScript pad function.

- Code:
<!--parser:xtscript-->
	# Assigning space into a variable using chr function so we can use space as the last character in script
	var $spa = call chr $val=32

	var $string = Let's GO

	var $string_a = call str_pad $val=$string; $pad_length=20; $pad_string=Ok$spa; $pad_type=STR_PAD_LEFT

	var $string_b = call str_pad $val=$string_a; $pad_length=25; $pad_string=!;

	var $string_c = call str_pad $val=$string_b; $pad_length=45; $pad_string=~; $pad_type=STR_PAD_BOTH

	print 1. $string <br/>
	print 2. $string_a <br/>
	print 3. $string_b <br/>
	print 4. $string_c
<!--/parser:xtscript-->
- Result:
1. Let's GO
2. Ok Ok Ok Ok Let's GO
3. Ok Ok Ok Ok Let's GO!!!!!
4. ~~~~~~~~~~Ok Ok Ok Ok Let's GO!!!!!~~~~~~~~~~