Library reference

Repeat a piece of text

Repeat the same text a given number of times. The new string contains each copy in order.

array repetition

Simple example

Repeat x three times.

Start'x' · 3
Resultxxx
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{s}\n", .{"x".* ** 3});
}
Output
xxx
Advertisements

Everyday examples

Print four star marks on a prize ticket.

Start'*' · 4
Result****
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{s}\n", .{"*".* ** 4});
}
Output
****

Draw a six-character divider for a receipt.

Start'-' · 6
Result------
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{s}\n", .{"-".* ** 6});
}
Output
------

Make a three-part red-blue pattern for a ribbon label.

Start'RB' · 3
ResultRBRBRB
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{s}\n", .{"RB".* ** 3});
}
Output
RBRBRB
Run the example
Terminal
zig run lesson.zig
Official documentation