Elixirの文字列、バイナリ、シジル
ElixirがテキストをUTF-8バイナリとして表現する方法を学び、シジルを使って文字列、リスト、正規表現を簡潔に記述します。
「Elixirの文字列、バイナリ、シジル」はCoddyKit上の無料Elixir & Phoenix: Scalable Backend Developmentレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはElixir & Phoenix: Scalable Backend Development学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Elixir & Phoenix: Scalable Backend Developmentコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Strings Are UTF-8 Binaries
An Elixir string is a UTF-8 binary in double quotes — not a list of characters. Keep that distinction in mind.
name = "Elixir"
IO.puts(name)String Concatenation
Join two strings with <>, which concatenates the underlying binaries.
greeting = "Hello, " <> "World"
IO.puts(greeting)String Interpolation
Drop expressions into a string with interpolation: the code is evaluated and its result slotted in.
name = "Ada"
IO.puts("Hello, #{name}!")Common String Functions
The String module is full of helpers for transforming text, like upcase and length.
IO.puts(String.upcase("elixir"))
IO.puts(String.length("hello"))Splitting and Trimming
Use String.split to break text into parts and String.trim to strip surrounding whitespace.
parts = String.split("a,b,c", ",")
IO.inspect(parts)
IO.puts(String.trim(" hi "))Strings vs Charlists
Single quotes make a charlist — a list of integers — not a string. Most modern APIs expect double-quoted strings.
IO.inspect('abc')
IO.inspect("abc")Introducing Sigils
A sigil starts with ~ and a letter for compact literals. For example, ~s builds a string.
text = ~s(He said "hi")
IO.puts(text)Word List Sigils
The ~w sigil builds a word list from whitespace-separated text — no noisy quotes or commas.
words = ~w(apple banana cherry)
IO.inspect(words)Atom Word Lists
Append the a modifier to ~w and you get a list of atoms instead of strings.
keys = ~w(name age email)a
IO.inspect(keys)Regex Sigils
The ~r sigil creates a regex, which you pair with the Regex module to match and replace.
IO.inspect(Regex.run(~r/\d+/, "abc123"))Heredocs for Multiline Text
Triple-quoted heredocs hold multi-line text and double as documentation strings.
msg = """
Line one
Line two
"""
IO.puts(msg)Quick Check
Test your Elixir string knowledge.
Recap
Recap: strings are UTF-8 binaries you join with <> and interpolate; the String module transforms them; charlists differ; and sigils keep literals concise.
よくある質問
「Elixirの文字列、バイナリ、シジル」レッスンは無料ですか?
はい。「Elixirの文字列、バイナリ、シジル」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Elixir & Phoenix: Scalable Backend Developmentコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Elixir & Phoenix: Scalable Backend Developmentコースには全4レッスンが含まれています。
「Elixirの文字列、バイナリ、シジル」で何を学びますか?
ElixirがテキストをUTF-8バイナリとして表現する方法を学び、シジルを使って文字列、リスト、正規表現を簡潔に記述します。 ブラウザで直接実行するハンズオンコードでElixir & Phoenix: Scalable Backend Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Elixir & Phoenix: Scalable Backend Developmentを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのElixir & Phoenix: Scalable Backend Developmentは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「Elixirの文字列、バイナリ、シジル」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このElixir & Phoenix: Scalable Backend Developmentレッスンでコードを書いて実行できますか?
はい。すべてのElixir & Phoenix: Scalable Backend Developmentレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Elixir言語入門
- 基本的なデータ型と演算子
- パターンマッチングと制御フロー
- Elixirの文字列、バイナリ、シジル