Working with Text
Text is everywhere in programs — names, messages, labels, output. In Clean Language, text is called a string, and there are a few things you'll do with strings constantly. Let's cover them all.
The most useful thing right away is string interpolation — putting a variable's value directly inside text using {}:
start:
string name = "Alice"
integer age = 28
print("Hello, my name is {name} and I am {age} years old.")Hello, my name is Alice and I am 28 years old.Much nicer than joining pieces together manually. Anything inside {} gets inserted right there in the text.
Here are the string operations you'll reach for most often:
start:
string message = " Hello, Clean Language! "
print(message.trim())
print(message.trim().toUpperCase())
print(message.trim().toLowerCase())
print(message.trim().length().toString())
print(message.contains("Clean").toString())
print(message.replace("Clean", "Beautiful").trim())Hello, Clean Language!
HELLO, CLEAN LANGUAGE!
hello, clean language!
22
true
Hello, Beautiful Language!Notice how you can chain operations — .trim().toUpperCase() — each one feeds into the next. It reads almost like a sentence.
Quick recap
- Use {variableName} inside a string to insert a value — no joining needed
- .trim() removes extra spaces from both ends
- .toUpperCase() and .toLowerCase() change the case
- .length() returns how many characters are in the string
- .contains(word) checks if a string includes something
- .replace(old, new) swaps text out
- Chain operations: .trim().toUpperCase()