XtScript Function: str_pad

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

XtScript pad function basic syntax:

  call str_pad $val=...; $pad_length=...; $pad_string=...; $pad_type=...

Available arguments in XtScript pad function:

Argument Mandatory Value Explanation
$pad_length Required Number Specified 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_string Optional String. space will be used as default value if this argument is not set. Specified the sting to be pad to the main string.
$pad_type Optional The 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.

    # 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
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!!!!!~~~~~~~~~~

By SiDar

Webmaster Assistant and Editor at

SiDar enjoying himself listening J-pop genre music and playing games, especially old school games. Sometimes he also found watching anime and reading manga are interesting when his fellow author recommend him some good titles.

Leave a Reply

Your email address will not be published. Required fields are marked *