Lesson contents

Working with strings

Join two pieces of text in the order you want them to appear.

Simple example

Join two letters.

StartA + B
ResultAB
lesson.zig
const std = @import("std");

pub fn main() !void {
    const line = "A" ++ "B";
    std.debug.print("{s}\n", .{line});
}
Output
AB
Advertisements

Everyday examples

A shelf label starts with the aisle letter and ends with the shelf number. Make the label for shelf 12 in aisle C.

StartC + 12
ResultC12
lesson.zig
const std = @import("std");

pub fn main() !void {
    const line = "C" ++ "12";
    std.debug.print("{s}\n", .{line});
}
Output
C12
Run the example
Terminal
zig run lesson.zig
Official documentation