Chapter 8. Strings

Strings are not like integers, floats, and Booleans. A string is a sequence, which means it is an ordered collection of other values. In this chapter you’ll see how to access the characters that make up a string, and you’ll learn about some of the string helper functions provided by Julia.

Characters

English language speakers are familiar with characters such as the letters of the alphabet (A, B, C, …), numerals, and common punctuation. These characters are standardized and mapped to integer values between 0 and 127 by the ASCII standard (American Standard Code for Information Interchange).

There are, of course, many other characters used in non-English languages, including variants of the ASCII characters with accents and other modifications, related scripts such as Cyrillic and Greek, and scripts completely unrelated to ASCII and English, including Arabic, Chinese, Hebrew, Hindi, Japanese, and Korean.

The Unicode standard tackles the complexities of what exactly a character is, and is generally accepted as the definitive standard addressing this problem. It provides a unique number for every character on a worldwide scale.

A Char value represents a single character and is surrounded by single quotes:

julia> 'x'
'x': ASCII/Unicode U+0078 (category Ll: Letter, lowercase)
julia> '🍌'
'🍌': Unicode U+01f34c (category So: Symbol, other)
julia> typeof('x')
Char

Even emojis are part of the Unicode standard (\:banana: TAB).

A String Is a Sequence

A

Get Think Julia now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.