Skip to content
Strings
step 1/5

Reading — step 1 of 5

Learn

~1 min readStrings and Pattern Matching

Strings are UTF-8 binaries. They support interpolation with #{...}:

name = "Alice"
age = 30
IO.puts "Hi, #{name}. You are #{age} years old."

The String module has the operations:

IO.puts String.length("hello")        # 5
IO.puts String.upcase("hello")          # HELLO
IO.puts String.contains?("hello", "ell") # true
IO.puts String.split("a,b,c", ",") |> inspect  # ["a", "b", "c"]
IO.puts String.reverse("hello")         # olleh

Strings are immutable — every operation returns a new string. Concatenation uses <>:

"hello" <> ", " <> "world"   # "hello, world"

Don't confuse with ++ (which is for lists).

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…

Strings — Elixir Fundamentals