String
A string value is a sequence of characters.
Definition
A string value can be defined using text enclosed in double quotes.
let message be "hello world"Or multiline with quote, followed by a sequence of lines starting with |.
let long_message be quote
| this is a
| multiline string
| with lots of words
| to be read
print long_messageIt can be interpolated with other values using {} delimiters. The
expression inside the {} will be converted using to_string.
let name be "Alice"
let age be 30
let greeting be "I'm {name} and I'm {age} years old."
print greetingUsage
Individual characters can be accessed using at, but not updated,
you must instead create a new string if you want to change it.
let message be "hello world"
print message at 0 # "h"Strings can be concatenated with other strings using the plus operator.
let hello be "hello" plus " " plus "world"
print hello # "hello world"Getters
Returns the number of characters in the string.
let message be "hello world"
print message's length # 11Methods
Returns a copy of itself.
let message be "hello world"
let stringified be call message's to_string
print stringified # "hello world"Returns a number parsed from the string, or blank if the string cannot be parsed
as a number.
let message be "42"
let numberified be call message's to_number
print numberified # 42Returns a lowercase version of the string.
let message be "Hello World"
let lowercase_message be call message's to_lowercase
print lowercase_message # "hello world"Returns a uppercase version of the string.
let message be "hello world"
let uppercase_message be call message's to_uppercase
print uppercase_message # "HELLO WORLD"Returns the same string but with the first character capitalized.
let message be "hello world"
let capitalized_message be call message's to_capitalize
print capitalized_message # "Hello world"Returns the same string but with the first character of each word capitalized.
let message be "hello world"
let capitalized_message be call message's to_capitalize_all
print capitalized_message # "Hello World"Returns a list of strings split by the delimiter, converted with to_string.
let message be "hello world"
let delimiter be " "
let split_message be call message's to_split with just delimiter
print split_message # "list with hello, and world"Returns a slice of the string. If end is not specified, it defaults to the end of
the string.
let message be "hello world"
let sliced_message be call message's to_slice with 0, and 5
print sliced_message # "hello"Returns the same string but with leading and trailing whitespaces removed.
let message be " hello world "
let trimmed_message be call message's to_trim
print trimmed_message # "hello world"