Curriculum Basics Strings as slices
Strings as slices
There's no String type in Zig. String literals are byte slices typed as []const u8 — same shape as any other slice of read-only bytes. Length comes from .len (a usize), indexing returns a single u8 byte, and substring with s[a..b] produces another []const u8. The mental model from TypeScript needs one shift: a Zig string isn't a value-typed character sequence, it's a view into bytes.
Exercises
9 ready
01
pick one
TypeScript writes const greeting: string = "hello";. Zig has
02
pick one
TypeScript reads s.length to get a string's length. Zig's
03
pick one
TypeScript's s.slice(start, end) returns a substring. Zig
04
fill blanks
Fill the missing property name. The property gives the length
05
fill blanks
Fill the missing type. The element type of a Zig byte slice
06
type one line
Type the missing Zig line — fetch the length of greeting into
07
type one line
Type the missing Zig line — the substring of "hello world"
08
write a program
Write a complete Zig program that:
09
write a program
Write a complete Zig program that: