Julia Characters Tutorial
last modified November 18, 2026
A character is a single symbol such as a letter, digit or punctuation
mark. In Julia the Char type represents one Unicode character,
which means it can hold symbols from many writing systems, not just ASCII.
Strings are sequences of these characters encoded as bytes.
This tutorial covers character literals, code points, escape sequences, classification, and how characters relate to Unicode strings. The examples were verified with Julia 1.13.4. Unicode identifiers in variable names are a separate topic covered in Julia variables.
Char Literals
A character literal is written between single quotes. Its type is
Char, and converting it to an integer reveals the numeric value
Julia assigns to the symbol.
c = 'A' println(c) println(typeof(c)) println(Int(c))
The literal 'A' creates a Char. Converting it with
Int gives 65, the standard numeric value of the capital letter A.
Note the difference from a String: a character uses single quotes,
while a string uses double quotes.
$ julia main.jl A Char 65
Code Points and codepoint
A code point is the number that the Unicode standard assigns to a
character. The codepoint function returns it, and the
Char constructor converts a hexadecimal code point back into a
character.
c = 'α'
println(codepoint(c))
println(Char(0x03B1))
println(codepoint('A'))
The Greek letter alpha has code point 945 in decimal, which is the hexadecimal
value 0x03B1. Passing that value to Char recreates the
same symbol. The letter A has code point 65, matching the result from the
previous section.
$ julia main.jl 945 α 65
Escape Sequences
An escape sequence is a backslash code inside a literal that stands
for a character that is hard to type directly. Common ones include
\n for newline, \t for tab and \\ for a
single backslash. The \u and \x forms specify a code
point in hexadecimal.
println(repr('\n'))
println(repr('\t'))
println(repr('\\'))
println('\u03b1')
println('\x41')
The repr function returns a readable representation of a value, so
printing it shows the escape codes themselves rather than the whitespace they
represent. The last two lines create characters directly from hexadecimal
code points: '\u03b1' is the Greek letter alpha and
'\x41' is the letter A.
$ julia main.jl '\n' '\t' '\\' α A
Character Classification
Julia provides predicates that answer questions about a character. The
functions isletter, isdigit and isspace
return true or false depending on the category the
character belongs to, and they work with Unicode as well as ASCII.
for c in ['a', '7', ' ', 'α', '+']
println(c, " ", isletter(c), " ", isdigit(c), " ", isspace(c))
end
The letter a and the Greek alpha are letters; 7 is a digit; the space character is whitespace; and the plus sign belongs to none of these three categories. Each line prints the character followed by the three boolean answers.
$ julia main.jl a true false false 7 false true false false false true α true false false + false false false
Unicode Strings and Byte Lengths
A String stores characters as UTF-8 bytes, so the number of bytes
is not always the same as the number of characters. The length
function counts characters, sizeof counts bytes, and
lastindex gives the largest valid byte index.
s = "αβγ" println(length(s)) println(sizeof(s)) println(lastindex(s))
Each of the three Greek letters occupies two bytes in UTF-8, so the string has three characters but six bytes. Its last valid byte index is five, because indexes count bytes and the final character occupies bytes five and six. A full discussion of byte indexing and string functions is in Julia string functions.
$ julia main.jl 3 6 5
Indexing a String Returns a Char
Indexing a string with a valid byte position gives back a single
Char, not a one-character string. This distinction matters when
writing code that inspects text one symbol at a time.
s = "Julia"
c = s[1]
println(c)
println(typeof(c))
println(typeof("a"))
The first element of "Julia" is the character 'J',
whose type is Char. By contrast, the double-quoted
"a" is a String even though it contains only one
character.
$ julia main.jl J Char String
Building a String from Characters
The reverse operation is also possible: a collection of characters can be
joined into a single string with the String constructor.
chars = ['J', 'u', 'l', 'i', 'a'] s = String(chars) println(s)
The vector of five characters becomes the string "Julia". This is
handy when processing text character by character and then assembling the
result.
$ julia main.jl Julia
Case Conversion and Comparison
Characters can be converted between upper and lower case, and they can be compared with the usual relational operators. Comparison follows code point order, which corresponds to alphabetical order for ordinary letters.
println(uppercase('a'))
println(lowercase('A'))
println(uppercase('α'))
println('a' < 'b')
println('A' == 'A')
The first two calls perform the expected ASCII case conversion, and
uppercase also works on the Greek letter alpha, producing the
capital form. The comparison 'a' < 'b' is true because a has a
smaller code point, and two identical characters compare equal.
$ julia main.jl A a Α true true
A Note on Normalization
Unicode text can represent the same visible symbol in more than one way. For example, a letter with an accent may be stored as a single combined code point or as a base letter followed by a separate combining accent. Julia's Base library does not provide full Unicode normalization, so two strings that look identical may compare as different.
If your work requires canonical composition, decomposition or other normalization forms, use an external package that implements the Unicode normalization algorithms. Do not attempt to normalize text by hand with the basic character functions described here.
Best Practices for Characters
A few habits make character handling predictable.
- Use single quotes for one character: double quotes create
a
String, not aChar. - Work with code points, not raw bytes: use
codepointandCharrather than assuming characters fit in one byte. - Use
lastindexwhen indexing strings: byte positions can fall in the middle of a multibyte character. - Reach for a package for normalization: Base does not normalize Unicode text.
Source
Julia Characters documentation
Julia Base Characters documentation
In this article we have explored Julia characters: literals, code points, escape sequences, classification, Unicode strings and byte lengths. Strings in general are introduced in Julia strings and manipulated in Julia string functions; regular expressions are covered in Julia regex.
Author
List all Julia tutorials.