Skip to content

10 · Strings

Literals and Escapes

Double quotes, escape sequences (\n \t \" \\) and the char type.

On this page

Every string in Zolo uses double quotes. There is no single-quote string syntax — 'a' is a character literal (type char), useful in comparisons but distinct from str.

The basic escape sequences are \n (newline), \t (tab), \" (quote inside a string), and \\ (literal backslash):

Literals, escapes, and the .len() method on simple strings.

01-literals-and-escapes.zolo
Playground
// Feature: Strings — literals and escape sequences

// Syntax: `"..."`, `"""..."""`, and raw `r"..."` strings

// When to use: represent text. Single quotes are CHAR literals.


// Strings always use double quotes.

let greeting = "Hello, world!"
print(greeting)

// expected: Hello, world!


// Basic escape sequences.

print("line 1\nline 2")  // \n line break

print("col1\tcol2\tcol3")  // \t tab

print("quote: \"")  // \" literal quote inside string
print("slash: \\")  // \\ literal backslash

print("return: end\rstart")  // \r carriage return


// Single quotes are CHAR literals (1 character only).

// Useful for character comparisons, not strings.

let c = 'a'
print(c == 'a')

// expected: true


// Cooked strings and character literals accept Unicode scalar escapes.

print("Açaí - café")
print("emoji: \u{1F680}")
print('\u{03BB}')

// Empty strings and single-char strings.

let empty = ""
let s = "x"
print(empty.len())  // 0

print(s.len())  // 1

Challenge

Create a string containing a backslash followed by a literal n (i.e. the two characters \ and n, not a newline). Print it and confirm the output shows \n and not a blank line.

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br