Strings In Depth13 / 19
Up next

Find a substring

const std = @import("std");

pub fn main() void {
    const haystack = "hello world";
    // indexOf returns ?usize: the start offset, or null
    if (std.mem.indexOf(u8, haystack, "world")) |at| {
        std.debug.print("found at {d}\n", .{at});
    } else {
        std.debug.print("not found\n", .{});
    }
}
What you're solving

std.mem.indexOf returns an optional index