Course
BASICModule 3: Data & Structures· 2/3

Working with Strings

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

PLAYGROUND

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:

PLAYGROUND

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:

PLAYGROUND

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.

PLAYGROUND

Key takeaways

  • Normalize strings from the outside world first: trim/strip + lowercase.
  • split cuts a string into an array, join glues 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.
CHECK YOURSELF
1. User input "Anna@Mail.com " did not match "anna@mail.com" in the database. What was forgotten?
2. How do you turn the string "ETH;2.5;3200" into an array of three parts?
Arrays & ObjectsJSON