ToString
Copies the contents out into a string.
Module: Text
Signature
rux
func ToString(self) -> String;Returns
A String holding a copy of the bytes written so far, in a block of its own. An empty builder yields the empty string.
The builder keeps its own block and stays usable, so both it and the String own a block and both have to be freed. Reach for IntoString instead once the builder is finished with: that one hands the block over rather than copying it.
Taking a snapshot mid-build is what this is for — the String will not follow the builder's later appends.
Example
rux
import Text::StringBuilder;
var builder = StringBuilder::New();
builder.Append("Rux");
var snapshot = builder.ToString(); // "Rux", its own block
builder.Append(" rocks"); // the snapshot does not change
snapshot.Length(); // 3
snapshot.Free();
builder.Free(); // both own a blockSee also
StringBuilder— the builder typeIntoString— hand the block over instead of copying itString::Clone— the same copy, from a string