Game Maker Games, Articles, Tutorials & More

Game Maker Network


Howdy, Guest! Please sign in or register an account.

Print

string_pad

By Daniel · January 11, 2009

Pads some string to a certain length by applying some pad string on the direction of choice.

/* string_pad(str, pad_len, pad_str, left)
 *
 * Pads some string (str) to a certain length (pad_len) using pad_str. If
 * left is true, the padding will be applied on the left side; otherwise it
 * will be applied on the right.
 */

var size, pad;

size = max(0, argument1 - string_length(argument0));

pad = (size div string_length(argument2)) * argument2
    + string_copy(argument2, 1, size mod string_length(argument2));

return argument3 * pad + argument0 + (!argument3) * pad;

Categories: String handling

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.

Advertisement