logo Dorpn v0.4.1 GitHub
API Reference

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()

"string".repeat(times) Method

Creates a new string consisting of the original string repeated a specified number of times. Does not insert separators between repetitions.

  • timesAn Int specifying how many times to repeat the string. Must be non-negative.
dorpn
tag stars = "*".repeat(10)
tag hello = "Hi ".repeat(3)
print(stars)    # Output: **********
print(hello)    # Output: Hi Hi Hi

print("=".repeat(5))  # Output: =====

.alter()

"string".alter(target, replacement) Method

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.

dorpn
tag text = "Hello World"
tag new_text = text.alter("World", "Dorpn")
print(new_text)  # "Hello Dorpn"

.flip()

"string".flip() Method

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.

dorpn
tag reversed = "hello".flip()
tag palindrome = "racecar".flip()
print(reversed)    # "olleh"
print(palindrome)    # "racecar"

.size()

"string".size() Method

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.

dorpn
tag length = "Hello".size()  # 5
tag empty = "".size()        # 0

# With variables
tag name = "Alice"
print("Name length:", name.size())
Chaining
Because every string method returns a new String, calls can be chained: "dorpn".flip().repeat(2) reverses the string, then repeats the result twice.