The String Toolkit — Clean Language
← All tutorials
language-deep-dive6 min

The String Toolkit

Strings have a rich set of built-in methods. This tutorial covers the ones you will use most — not a complete reference, but the practical toolkit for real programs: parsing input, transforming text, and splitting data.

Inspection and normalization — the first thing to do with any user input:

start:\n    string raw = "  Hello, Clean Language!  "\n    string clean = raw.trim()\n\n    print("Length before: " + raw.length().toString())\n    print("Length after: " + clean.length().toString())\n    print("Upper: " + clean.toUpperCase())\n    print("Lower: " + clean.toLowerCase())\n    print("Has 'Clean': " + clean.contains("Clean").toString())\n    print("Starts with 'Hello': " + clean.startsWith("Hello").toString())\n    print("Ends with '!': " + clean.endsWith("!").toString())
Length before: 26\nLength after: 22\nUpper: HELLO, CLEAN LANGUAGE!\nLower: hello, clean language!\nHas 'Clean': true\nStarts with 'Hello': true\nEnds with '!': true

.trim() removes leading and trailing whitespace — always call it on user input before doing anything else. .contains(), .startsWith(), and .endsWith() return boolean and work directly in if conditions.

Transformation and parsing — working with structured text:

start:\n    string title = "Hello World From Clean Language"\n    string slug = title.toLowerCase().replace(" ", "-")\n    print(slug)\n\n    string csv = "alice,bob,charlie,diana"\n    list<string> names = csv.split(",")\n    iterate name in names\n        print("- " + name.trim())\n\n    string code = "PROMO2026"\n    string prefix = code.slice(0, 5)\n    string suffix = code.slice(5, 9)\n    print("Prefix: " + prefix + ", Suffix: " + suffix)
hello-world-from-clean-language\n- alice\n- bob\n- charlie\n- diana\nPrefix: PROMO, Suffix: 2026

.replace(from, to) swaps every occurrence — method calls chain naturally. .split(delimiter) returns a list, which you can iterate immediately. .slice(start, end) extracts a substring by character position.

Quick recap

  • .trim() removes whitespace from both ends — always use on user input
  • .contains(), .startsWith(), .endsWith() return boolean for use in if conditions
  • .replace(from, to) replaces all occurrences — chain with other methods
  • .split(delimiter) returns list — iterate over the result immediately
Copied!