Strings & Text
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
- Arrays & ListsProgramming Fundamentals
A string is a specialized sequence of characters; string operations (indexing, slicing, iteration) are the same operations arrays support, applied to character elements.
Helps
- Number Systems & BasesMathematical Thinking
Character encodings (ASCII, UTF-8) map characters to numbers via a lookup table; understanding bases and how numbers are represented clarifies why encoding bugs (mojibake, truncated emoji) happen.
Unlocks
Used in
- Text encoding standards (ASCII, UTF-8, UTF-16) used by every file, network protocol, and database
- String search algorithms in text editors, search engines, and grep
- Templating and serialization (JSON/HTML string building)
- Internationalization (i18n) — handling multi-byte characters correctly
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
- I can explain what a character encoding is and why it's needed
- I can explain why a string's length isn't always what it looks like in languages with UTF-16 strings
- I can implement basic string algorithms (reverse, search) using array reasoning
- I can identify an encoding-related bug from its symptoms (mojibake, truncation)