Hello everyone. I’m new to Zig and might not understand something around here.
I’m following learning Introduction Book to Zig, and I’m on this section which talks about std.mem.replace
method. I’m confused, because my buffer is cleared out after running said method.
Code example:
{
// Replace
const s7: []const u8 = "Hello";
var buf = [8]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
const count = mem.replace(u8, s7, "el", "34", buf[0..5]);
std.debug.print("N of replacements: {d}\n", .{count});
std.debug.print("New string: {s}\n", .{buf});
}
// Expected output:
N of replacements: 1
New string: H34lo678
// Actual output:
N of replacements: 1
New string: H34lo
Could you please expalin why this is happening? Thanks.