The OpenD Programming Language

center

Center s in a field width characters wide. fillChar is the character that will be used to fill up the space in the field that s doesn't fill.

S
center
(
S
)
(
S s
,
size_t width
,
dchar fillChar = ' '
)

Parameters

s S

The string to center

width size_t

Width of the field to center s in

fillChar dchar

The character to use for filling excess space in the field

Return Value

Type: S

The resulting center-justified string. The returned string is GC-allocated. To avoid GC allocation, use centerJustifier instead.

Examples

assert(center("hello", 7, 'X') == "XhelloX");
assert(center("hello", 2, 'X') == "hello");
assert(center("hello", 9, 'X') == "XXhelloXX");

Meta