Strings & Text

Difficulty
Importance

The problem

Nearly every program handles human-readable text — names, messages, file contents — and needs a reliable way to store, compare, search, and transform sequences of characters, including characters far beyond the 26 English letters.

Why now

Arrays and lists give the general 'ordered sequence' structure, but text has its own wrinkles — how a character maps to a number (encoding), and why 'length' isn't always what it looks like once non-English characters are involved. Number systems and bases already explained positional representation; text encoding is that same idea applied to characters instead of digits.

Mental model

A string is an array of character codes wearing a friendlier face — each visible character is really just a number (via an encoding table like UTF-8), and 'string operations' are array operations with text-specific conveniences (comparison, searching, splitting) layered on top.

Requires

Helps

Unlocks

Used in

Projects

  • Write a function that reverses a string correctly even with multi-byte (emoji/accented) characters, then break a naive byte-reversal implementation to see why it fails
  • Implement your own indexOf/substring functions using only array operations

Examples

  • 'A'.charCodeAt(0) === 65 — the letter is really just the number 65 under UTF-8/ASCII
  • '👍'.length === 2 in JavaScript because the emoji is encoded as two UTF-16 code units, not one — a direct consequence of the encoding, not a language bug

Resources

Mastery checklist