Basic Types

Boolean

In Elixir, the only values considered falsy are false and nil, same as Clojure.

String

Double quotes (") create a binary string (UTF-8 encoded)

msg = "鯖の塩焼き"
is_binary(msg)
# true
byte_size(msg)
# 15
String.at(msg, 1)
# "の"
byte_size("über")
# 5

Single quotes (') create a character(integer) list, which is deprecated, use ~c if you want a list.

chars = ~c"atoz"
is_list(chars)
# true
hd(chars)
# 97

heredoc

"""
Hello,
Alice
"""
# "Hello,\nAlice\n"

String concatenation

name = "Alice"
"Hello, " <> name <> "!"
# "Hello, Alice!"

String interpolation

name = "Alice"
"Hello, #{name}!"
# "Hello, Alice!"

interpolation not work with ~S and ~C

name = "Alice"
~S"Hello, #{name}!"
# "Hello, \#{name}!"

The String module

import String

name = "Alice"
"Hello, #{upcase(name)}!"
# "Hello, ALICE!"

contains? "abc", "b"
# true

trim " hello\n"
# hello

replace "hello", "e", "a"
# "hallo"