Comparing and Searching Bytes
Use std.mem helpers on strings.
You Cannot Use ==
Two slices are different windows, so == compares pointers and lengths, not contents. Comparing text needs a real byte-by-byte check.
std.mem to the Rescue
The standard library module std.mem works on slices of any element type, and that includes your []const u8 strings.
const std = @import("std");
const mem = std.mem;All lessons in this course
- Strings Are []const u8
- String Literals and Escapes
- Comparing and Searching Bytes
- Formatting Text with std.fmt