Strings
A string holds text. The type is string, and a literal is inside double
quotation marks.
def text "Hello World"The common operators
Section titled “The common operators”def text "Hello World"
def len (strlen text) ; 11def sub (substring text 0 5) ; "Hello"
def lower (to_lowercase text) ; "hello world"def upper (to_uppercase text) ; "HELLO WORLD"
def idx (indexOf text "World") ; 6def hasWorld (contains text "World") ; truedef starts (startsWith text "Hello") ; truedef ends (endsWith text "World") ; true
def replaced (replace text "World" "Ranger") ; "Hello Ranger"def parts (strsplit text " ") ; ["Hello", "World"]def trimmed (trim " hello ") ; "hello"The operators are in prefix form: the operator is first and the arguments are after it.
Concatenation
Section titled “Concatenation”The + operator joins two strings. A value of another type needs a conversion
first, except in a print statement, where the compiler adds the conversion.
def count 3print ("count " + count)def label ("count " + (to_string count))The index of a character
Section titled “The index of a character”The index of a character is a code point index. A target language that counts bytes or UTF-16 units gets the operation that gives the same result as the other targets. A program therefore reads the same character at the same index on each target language.
The complete list
Section titled “The complete list”The string operators page holds each operator with its signature, its target support and the code that it writes for each target language.
Ranger 3.5.1 · commit f323fd4 · development build