Strings & Characters
Strings use byte indices; not every index is valid for multi-byte characters:
6.1 Basics
s = "Hello, Julia"
length(s) # 12 characters
sizeof("héllo") # 6 bytes (UTF-8)
s[1] # 'H' — indexing is 1-based, by BYTE index
s[end] # 'a'
s[1:5] # "Hello"
s * "!" # concatenation uses *
"ab" ^ 3 # "ababab"
"Value: $(1 + 2)" # interpolation
name = "Ann"; "Hi, $name"
"""
Multi-line
string
"""
raw"C:\path\no\escapes"6.2 String functions
uppercase(s), lowercase(s), titlecase("hello world"), uppercasefirst("abc")
occursin("Julia", s), startswith(s, "He"), endswith(s, "ia")
findfirst("Julia", s) # 8:12
findfirst('l', s), findlast('l', s), findall('l', s)
replace(s, "Julia" => "World")
replace("a-b_c", "-" => " ", "_" => " ")
split("a,b,c", ",") # ["a", "b", "c"]
join(["a", "b", "c"], ", ")
strip(" hi "), lstrip(" hi"), rstrip("hi "), chomp("line\n")
reverse("abc"), repeat("ab", 2), lpad("7", 3, '0'), rpad("x", 3, '.')
collect("abc") # ['a', 'b', 'c']
string(1, " + ", 2)
isdigit('7'), isletter('a'), isspace(' '), isuppercase('A')
codepoint('A'), Char(0x263A)
cmp("a", "b"), "apple" < "banana"
chop("hello"), first("hello", 3), last("hello", 2)
eachsplit("a b c"), eachline(io)6.3 Unicode & indexing
Strings use byte indices; not every index is valid for multi-byte characters:
s = "αβγ"
s[1] # 'α'
# s[2] # StringIndexError — inside 'α'
nextind(s, 1) # 3
for c in s; print(c, " "); end # iterate characters safely
eachindex(s) |> collect # valid indices: [1, 3, 5]6.4 Formatting
using Printf
@printf("%.2f | %5d | %-8s|\n", π, 42, "left")
str = @sprintf("%08.3f", 3.14159)
string(round(π; digits=3))6.5 Regular expressions
r = r"(\d{4})-(\d{2})-(\d{2})"
m = match(r, "Date: 2026-10-25")
m.captures # ["2026", "10", "25"]
m[1] # "2026"
occursin(r"^\d+$", "12345") # true
[m.match for m in eachmatch(r"\d+", "a1b22c333")] # ["1", "22", "333"]
replace("a1b2", r"\d" => "#") # "a#b#"
replace("John Smith", r"(\w+) (\w+)" => s"\2, \1") # "Smith, John"
r"hello"i # case-insensitive flag
named = match(r"(?<year>\d{4})", "in 2026"); named[:year]6.6 Symbols
:apple # interned identifier, fast comparison
Symbol("apple") === :apple
string(:apple)