Strings & Unicode
Nested lists of binaries, bytes (0–255), and iolists; no concatenation needed:
14.1 Two string representations
List string (charlist) legacy APIs, small strings Binary string modern code, efficient storage, I/O Unicode binary
14.2 The string module (Unicode-aware, works on both)
string:length("héllo"), % 5 (grapheme clusters)
string:uppercase(<<"abc">>), % <<"ABC">>
string:lowercase("ABC"),
string:titlecase("hello"),
string:trim(" hi "),
string:trim("xxhixx", both, "x"),
string:split("a,b,c", ","), % ["a","b,c"]
string:split("a,b,c", ",", all), % ["a","b","c"]
string:lexemes("a b c", " "), % ["a","b","c"]
string:replace("hello", "l", "L", all),
string:find("hello world", "wor"), % "world"
string:slice("hello", 1, 3), % "ell" (0-based)
string:reverse("abc"),
string:pad("7", 3, leading, $0), % "007"
string:to_integer("42abc"), % {42,"abc"}
string:to_float("3.14"),
string:equal("a", "A", true), % case-insensitive
string:join(["a", "b"], ", "), % (obsolete; use lists:join + unicode:characters_to_binary)
string:prefix("prefix_rest", "prefix_"). % "rest"14.3 Conversions & Unicode
unicode:characters_to_binary("héllo"), % <<"héllo"/utf8>>
unicode:characters_to_list(<<"héllo"/utf8>>),
binary_to_list(<<"abc">>), list_to_binary("abc"),
io:format("~ts~n", [<<"héllo"/utf8>>]). % ~ts prints Unicode14.4 iolists — efficient output
Nested lists of binaries, bytes (0–255), and iolists; no concatenation needed:
Html = ["<p>", Name, "</p>", [<<"\n">>]],
iolist_to_binary(Html),
iolist_size(Html),
file:write_file("out.html", Html).14.5 Triple-quoted strings & sigils (OTP 27+)
Text = """
Multi-line text.
Indentation of the closing delimiter is stripped.
""",
B = ~"binary string, UTF-8 by default", % <<"..."/utf8>>
R = ~B"raw\nno escapes",
S = ~s"list string".14.6 Regular expressions (re, PCRE)
re:run("abc123", "\\d+"), % {match,[{3,3}]}
re:run("abc123", "\\d+", [{capture, all, binary}]), % {match,[<<"123">>]}
re:run(<<"2026-10-25">>, "(\\d+)-(\\d+)-(\\d+)", [{capture, all_but_first, list}]),
re:replace("a b c", "\\s+", " ", [global, {return, list}]), % "a b c"
re:split("a,b;c", "[,;]", [{return, list}]),
{ok, MP} = re:compile("^[a-z]+$", [caseless]),
re:run("Hello", MP).