BasicString.resize

Resizes the string to a length of n characters (utf code units).

If n is smaller than the current string length, the current value is shortened to its first n character, removing the characters beyond the nth.

If n is greater than the current string length, the current content is extended by inserting at the end as many characters as needed to reach a size of n.

If ch is specified, the new elements are initialized as copies of ch, otherwise, they are _.

struct BasicString
scope
void
resize
(
const size_t n
,
const CharType ch = '_'
)

Examples

BasicString!char str = "123";

str.resize(5, 'x');
assert(str == "123xx");

str.resize(2);
assert(str == "12");

Meta