Skip to content

10 · Strings

Case and Trim

.upper, .lower, .trim, .trim_start and .trim_end for normalizing text.

On this page

Strings are immutable: .upper() and .lower() return a transformed copy — the original string does not change. This makes normalization patterns safe: for example, lowercasing everything before a comparison:

.upper / .lower for case conversion; .trim / .trim_start / .trim_end to strip whitespace.

05-case-and-trim.zolo
Playground
// Feature: Case conversion and whitespace trimming
// Syntax: `s.upper()`, `s.lower()`, `s.trim()`, `s.trim_start()`, `s.trim_end()`
// When to use: normalize input, case-insensitive comparisons, clean input.

// -- upper / lower ---------------------------------------------
print("zolo".upper())
// expected: ZOLO
print("ZOLO".lower())

// expected: zolo

// Strings are immutable — methods return a transformed copy.
let s = "MiXed"
let u = s.upper()
print(u)  // MIXED
print(s)  // MiXed (original untouched)

// Case-insensitive comparison.
let input = "ADMIN"
let role = "admin"
print(input.lower() == role.lower())

// expected: true

// -- trim — removes whitespace from both ends ------------------
let pad = "  hello  "
print("'{pad.trim()}'")

// expected: 'hello'

// Only one side:
print("'{pad.trim_start()}'")  // 'hello  '
print("'{pad.trim_end()}'")  // '  hello'

// Useful for cleaning user input.
let raw = "   [email protected]   "
let email = raw.trim().lower()
print(email)
// expected: [email protected]

Challenge

Take an input with extra spaces and mixed case, such as " ZoLo LaNG ". Use .trim() and .lower() chained together to normalize it to "zolo lang".

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br