Strings In Depth15 / 19
Up next

Split on a byte

const std = @import("std");

pub fn main() void {
    const csv = "a,b,c";
    // each piece is a slice into the original buffer, no copies
    var it = std.mem.splitScalar(u8, csv, ',');
    while (it.next()) |field| {
        std.debug.print("[{s}]", .{field});
    }
    std.debug.print("\n", .{});
}
What you're solving

splitScalar yields borrowed pieces