Built-in String Methods
Method-style calls on String values, invoked with dot syntax:
"string".method(args). All string methods are non-mutating — they always return a new string.
.repeat()
Creates a new string consisting of the original string repeated a specified number of times. Does not insert separators between repetitions.
- timesAn
Intspecifying how many times to repeat the string. Must be non-negative.
tag stars = "*".repeat(10)
tag hello = "Hi ".repeat(3)
print(stars) # Output: **********
print(hello) # Output: Hi Hi Hi
print("=".repeat(5)) # Output: =====
.alter()
Creates a new string by replacing occurrences of a substring with another substring. The original string
is not modified — .alter() always returns a new string.
tag text = "Hello World"
tag new_text = text.alter("World", "Dorpn")
print(new_text) # "Hello Dorpn"
.flip()
Returns a new string with the characters of the original string reversed. Useful for palindrome detection, formatting, and general string manipulation. Does not modify the original string — you must assign or use the returned value.
tag reversed = "hello".flip()
tag palindrome = "racecar".flip()
print(reversed) # "olleh"
print(palindrome) # "racecar"
.size()
Returns the length of a string, measured in the number of characters it contains. Always returns an
Int. Useful for validation, loops, and formatting tasks.
tag length = "Hello".size() # 5
tag empty = "".size() # 0
# With variables
tag name = "Alice"
print("Name length:", name.size())
String, calls can be
chained: "dorpn".flip().repeat(2) reverses the string, then repeats the result twice.