Strings In Depth19 / 19
Up next

Join with a separator

const std = @import("std");

pub fn main() !void {
    const alloc = std.heap.page_allocator;
    const words = [_][]const u8{ "a", "b", "c" };
    // join is concat with a separator between pieces
    const csv = try std.mem.join(alloc, ",", &words);
    defer alloc.free(csv);
    std.debug.print("{s}\n", .{csv});
}
What you're solving

std.mem.join inserts a delimiter