liveBook · Manning

String

As explained in Elixir in Action, Third Edition

String is the Elixir standard-library module providing functions for working with UTF-8 encoded binaries and related textual data.

String is Elixir’s module-based abstraction for working with binary strings, commonly represented by double-quoted syntax. Functions receive data explicitly, and transformations return new values because strings are immutable. section 2.4.8 section 4.0

Use the binary-string forms that match the required syntax:

  • Interpolate expressions with #{}, escape characters conventionally, or use heredocs for formatted multiline strings. section 2.4.8
  • Use ~s for sigil strings; use uppercase ~S when interpolation and escape handling should remain disabled. section 2.4.8
  • Concatenate binary strings with <> and chain String functions by retaining each returned value. section 2.4.8 section 4.0
  • Prefer binary strings over character lists; charlists are integer-code-point lists and are not compatible with most String operations. section 2.4.8
iex(10)> "String" <> " " <> "concatenation"
"String concatenation"

Inspect binary-string concatenation with the <> operator. section 2.4.8

How Elixir in Action, Third Edition covers it

How deep it goes
Explains representations, syntax variants, immutability, concatenation, and charlists, but does not detail individual String APIs.
Examples
Demonstrates interpolation, escaping, sigils, heredocs, concatenation, IO output, and conversion between strings and charlists.
What it assumes
Assumes basic Elixir expressions and lists while establishing binary strings, charlists, modules, and immutable updates.
What you can do after
Apply String functions to immutable binary strings and choose between binary-string and charlist representations.
How it connects
Connects binary strings with modules, binaries, lists, character lists, sigils, interpolation, heredocs, and immutability.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.