String values deserve thier own section because they require memory allocation which we'll cover a bit later. Strings use the `strings` package to perform various manipulations.
use fmt;
use strings;
export fn main() void = {
// Concatinate strings together into one string
const concat = strings::concat("con", "cat")!;
fmt::println(concat)!;
free(concat);
// Join strings together
const join = strings::join(",", "one", "two", "three")!;
fmt::println(join)!;
free(join);
// Cut a string into pieces
const (begin, end) = strings::cut("beginning\nending", "\n");
fmt::println("begin:", begin)!;
fmt::println("end:", end)!;
};
$ hare run strings.ha
4/4 tasks completed (100%)
concat
one,two,three
begin: beginning
end: ending
Back to table of contents