O'Reilly logo

Programming Elixir by Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

String Literals

Elixir has two kinds of string: single-quoted and double-quoted. They differ significantly in their internal representation. But they also have many things in common.

  • Strings can hold characters in UTF-8 encoding.

  • They may contain escape sequences:

    \a

    BEL (0x07)

    \b

    BS (0x08)

    \d

    DEL (0x7f)

    \e

    ESC (0x1b)

    \f

    FF (0x0c)

    \n

    NL (0x0a)

    \r

    CR (0x0d)

    \s

    SP (0x20)

    \t

    TAB (0x09)

    \v

    VT (0x0b)

    \xhhh

    1–6 hex digits

  • They allow interpolation on Elixir expressions using the syntax #{...}.

     
    iex>​ name = "dave"
     
    "dave"
     
    iex>​ "Hello, #{String.capitalize name}!"
     
    "Hello, Dave!"
  • Characters that would otherwise have special meaning can be escaped with a backslash.

  • They support heredocs.

Heredocs

Any string can span several lines. To illustrate this, we’ll use both ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required