0PricingLogin
Zig Academy · Lesson

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

  1. Strings Are []const u8
  2. String Literals and Escapes
  3. Comparing and Searching Bytes
  4. Formatting Text with std.fmt
← Back to Zig Academy