Back to course

String Handling in Zig

Full Course: Zig Programming From Zero to Hero

Strings

In Zig, strings are just null-terminated arrays of u8 bytes. There is no special String type.

zig const hello = "Hello, Zig!"; // Type is *const [11:0]u8

To concatenate strings at runtime, you must use an allocator and std.fmt.allocPrint.

zig const name = "Alice"; const greeting = try std.fmt.allocPrint(allocator, "Hello, {s}!", .{name}); defer allocator.free(greeting);