HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to ElixirVariablesData TypesOperatorsStringsListsConditions (if / else)Iteration (Enum)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 List & Enum
🔀 Condition
🧩 Function
Elixir›Strings

Strings

Concatenation (<>), length (String.length), case conversion, and search.

Simple enough for a 5-year-old to understand

Concatenation and interpolation

Strings are concatenated with <>. The most readable way is #{} interpolation.

Example code
1
name = "Alex"
2
IO.puts("Hello " <> name)
Hello Alex (concatenation with <>)
Output / InputHello Alex (concatenation with <>)
3
IO.puts("Name: #{name}")
Name: Alex
Output / InputName: Alex
Output / Input
💡 Hint: String concatenation uses <>; you embed numbers with #{} .

About this topic

In Elixir, strings are stored as binary data and encoded in UTF-8. They are written in double quotes. Things written in single quotes are character lists, not strings; they exist for Erlang compatibility and are not used in everyday code.

Not knowing this distinction leads to confusing bugs: you get unexpected results from functions without realizing you are working with two different types. The rule is simple — use double quotes.

Interpolation syntax is used to inject values into a string. This structure accepts any expression and automatically converts the value to a string. It is both shorter than the concatenation operator and handles the conversion for you.

What you will learn

  • The difference between strings and character lists
  • String interpolation
  • Measuring length
  • String functions
  • The consequences of immutability

Who is this for?

  • Elixir developers who will process strings
  • Those who mix up single and double quotes
  • Those who get confused when measuring length

When to use?

Every message shown to the user and every field sent to the server is a string; interpolation makes up a large part of this code.

When calling Erlang libraries directly, a character list may be needed; conversion functions are for this situation.

Common mistakes

Wrong

metin = 'hello'
IO.puts String.length(metin)

Single quotes produce a character list, not a string; string functions do not work with this type and throw an error. In Elixir, strings are always written with double quotes. The fact that single quotes have a separate meaning is an unexpected distinction for those coming from other languages.

Correct

metin = "hello"
IO.puts String.length(metin)

Wrong

metin = "strawberry"
IO.puts byte_size(metin)

There is no error here, but the result is misleading: the number of bytes is greater than the number of letters because Turkish characters take up more than one byte. A separate function must be used to get the character count; confusing the two is very common.

Correct

metin = "strawberry"
IO.puts String.length(metin)

Wrong

metin = "hello"
String.upcase(metin)
IO.puts metin

Since data is immutable, the function does not change the original, it returns a new string. Since you didn't bind the result to anything, the lowercase version is still printed to the screen. This is the most frequently forgotten consequence of immutability.

Correct

metin = "hello"
metin = String.upcase(metin)
IO.puts metin

Frequently asked questions

How is interpolation syntax written?

You write the expression between a hash symbol and curly braces. You can put any expression inside it, and the result is automatically converted to a string. The difference from the concatenation operator is that it leaves no need for you to do the conversion.

How to write multi-line strings?

Three double quotes are used. The indentation of the closing mark determines where the string's indentation is counted from, which ensures that strings you write aligned in the source code look correct in the output.

How do I convert text to a number?

There are separate parsing functions for integers and floats. There are two versions: one that raises an error on invalid input and one that returns a status tuple instead of an error; the second one should be preferred for user input.

Summary

Strings are written with double quotes.

Single quotes produce a character list.

The number of bytes and the number of letters can be different.

String functions return a new value.

Interpolation does the conversion automatically.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code