Method code for $string.center()

[Turn on line numbering]
arg text, width, @args;
var fill, sides;

// args[1] <op> == what to fill the left|right side with.
// args[2] <op> == if exists also fill the right side.
[(fill ?= " "), (sides ?= 'left)] = args;
if (sides == 'both)
    return strfmt("%*{" + fill + "}c", width, text);
else
    return pad("", (width - strlen(text)) / 2, fill) + text;

["// Created 26-Mar-1995 as a part of ColdCore, see: @help Credit"]

the Cold Dark