#length of sentinel terminated

1 messages · Page 1 of 1 (latest)

rich stirrup
#

How do I get the length of a sentinel terminated slice/string?

vale garnet
#

slice.len

rich stirrup
#

Hmm, that's what I'm doing, and it isn't working as I expect.

#

My code looks like this:

var score_buf: [11:0]u8 = undefined;
if (std.fmt.bufPrint(&score_buf, "{}", .{snake1_score})) |_| {
    // ...
}
#

But when I call score_buf.len, the value is always 11.

vale garnet
#

bufPrint returns a slice into the buffer, use that

#

the buffer itself can't have its length changed

rich stirrup
#

Oh. So score_buf len will always be 11.

maiden crown
#

yea, its an array not a slice, length is constant

rich stirrup
#

Hmm. The buf returned always seems to be 11 too 🤔

vale garnet
#

show your code