#Cast []const u8 to [:0]const u8
1 messages · Page 1 of 1 (latest)
Do you know the last element of the slice is a 0?
In that case you can do
slice[0..slice.len - 1 :0]
The :0 means the element immediately after that is the sentinel value (0)
I have a string I was concatenating and passing to a raylib function which takes a [:0]const u8
so i used the ptrcast and needed to add ++ ""; at the end of my string.
const cwd: []const u8 = std.fs.path.dirname(current_dir()).?;
const asset_dir: []const u8 = cwd ++ "/../assets/";
pub fn loadAssets(comptime asset_name: []const u8) rl.Texture2D {
const asset: []const u8 = asset_dir ++ asset_name ++ "";
return rl.loadTexture(@as([:0]const u8, @ptrCast(asset)));
}```
which seems to work and loads texture correctly