Text is half of all data
Names, addresses, emails, logs, coupon codes, file contents — programs process text constantly. A string looks like a monolith, but it's really a sequence of characters with a rich set of operations.
The basic toolkit
Normalizing to a single form (trim/strip + toLowerCase/lower) is the mandatory first step before comparing strings from the outside world: users type with spaces and in any case, so "Anna@mail.com " and "anna@mail.com" are formally different strings.
Notice the call chains: email.trim().toLowerCase() — the result of one operation is immediately processed by the next. It reads left to right like a conveyor belt.
Cut and glue
Two workhorse operations: split cuts a string into an array by a separator, join glues an array into a string:
split is the foundation of parsing any structured text: CSV lines, logs, file paths. In the pro module on files it unfolds to its full power.
Template strings
Gluing with pluses ("Hi, " + name + "!") quickly becomes unreadable. Both languages can insert values straight into text:
JS uses backticks with ${...}, Python uses f-strings with {...}. Any expression works inside the braces. In modern code (and in code written by AI) template strings are the standard.
Exercise
From a full-name string make a signature in the format "V. Lastname": split by space, take the first letter of the name (s[0]), assemble it with a template string.
Key takeaways
- Normalize strings from the outside world first:
trim/strip+ lowercase. splitcuts a string into an array,joinglues it back — the foundation of parsing text.- Template strings (
`${}`/ f-strings) are the standard instead of gluing with pluses. - Call chains read like a conveyor belt, left to right.