Function String.shrink

Requests the string to reduce its capacity to fit the size.

void shrink (
  const(ulong) size
) pure nothrow @nogc @trusted;

The request is non-binding. The string won't become smaller than the string byte length.

Parameters

NameDescription
size Desired size.

Example

auto s = String("Die Alten lasen laut.");
assert(s.capacity == 21);

s.reserve(30);
s.shrink(25);
assert(s.capacity == 25);

s.shrink(18);
assert(s.capacity == 21);

s.shrink(22);
assert(s.capacity == 21);