Strings, Binaries & Sigils in Elixir
Explore how Elixir represents text as UTF-8 binaries and use sigils to write strings, lists, and regexes concisely.
Strings, Binaries & Sigils in Elixir is a free Elixir & Phoenix: Scalable Backend Development lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Elixir & Phoenix: Scalable Backend Development learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Strings Are UTF-8 Binaries
An Elixir string is a UTF-8 binary in double quotes — not a list of characters. Keep that distinction in mind.
name = "Elixir"
IO.puts(name)String Concatenation
Join two strings with <>, which concatenates the underlying binaries.
greeting = "Hello, " <> "World"
IO.puts(greeting)String Interpolation
Drop expressions into a string with interpolation: the code is evaluated and its result slotted in.
name = "Ada"
IO.puts("Hello, #{name}!")Common String Functions
The String module is full of helpers for transforming text, like upcase and length.
IO.puts(String.upcase("elixir"))
IO.puts(String.length("hello"))Splitting and Trimming
Use String.split to break text into parts and String.trim to strip surrounding whitespace.
parts = String.split("a,b,c", ",")
IO.inspect(parts)
IO.puts(String.trim(" hi "))Strings vs Charlists
Single quotes make a charlist — a list of integers — not a string. Most modern APIs expect double-quoted strings.
IO.inspect('abc')
IO.inspect("abc")Introducing Sigils
A sigil starts with ~ and a letter for compact literals. For example, ~s builds a string.
text = ~s(He said "hi")
IO.puts(text)Word List Sigils
The ~w sigil builds a word list from whitespace-separated text — no noisy quotes or commas.
words = ~w(apple banana cherry)
IO.inspect(words)Atom Word Lists
Append the a modifier to ~w and you get a list of atoms instead of strings.
keys = ~w(name age email)a
IO.inspect(keys)Regex Sigils
The ~r sigil creates a regex, which you pair with the Regex module to match and replace.
IO.inspect(Regex.run(~r/\d+/, "abc123"))Heredocs for Multiline Text
Triple-quoted heredocs hold multi-line text and double as documentation strings.
msg = """
Line one
Line two
"""
IO.puts(msg)Quick Check
Test your Elixir string knowledge.
Recap
Recap: strings are UTF-8 binaries you join with <> and interpolate; the String module transforms them; charlists differ; and sigils keep literals concise.
Frequently asked questions
Is the “Strings, Binaries & Sigils in Elixir” lesson free?
Yes — the full text of “Strings, Binaries & Sigils in Elixir” is free to read here on the web, and the Elixir & Phoenix: Scalable Backend Development course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Elixir & Phoenix: Scalable Backend Development course, upgrade to CoddyKit PRO.
What will I learn in “Strings, Binaries & Sigils in Elixir”?
Explore how Elixir represents text as UTF-8 binaries and use sigils to write strings, lists, and regexes concisely. You practise Elixir & Phoenix: Scalable Backend Development with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Elixir & Phoenix: Scalable Backend Development?
No prior experience is required. Elixir & Phoenix: Scalable Backend Development on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Strings, Binaries & Sigils in Elixir” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Elixir & Phoenix: Scalable Backend Development lesson?
Yes. Every Elixir & Phoenix: Scalable Backend Development lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Introduction to Elixir Language
- Basic Data Types and Operators
- Pattern Matching and Control Flow
- Strings, Binaries & Sigils in Elixir