Strings
Construction
A string can be written inline between a single pair of double quotes or via a multi-line block between three pairs of double-quotes.
Inline
An example of an inline string is "abc".
A double quote can appear in an inline string by escaping it with \ as in "ab\"cd".
Here is a list of some characters that can be expressed via escaping:
"via\",- a tab via
\t, - a new line via
\n, and \via\\.
Block
Here is an example of a block string, which is defined using three pairs of double quotes.
myMultiLineString =
"""
This is the first line of my "string"
and this is the last line.
""";
where the text is interprated literally. In particular, all white space is included and all escape sequences are ignored.
Operations
The following operations are available on strings.
length(x): the number of characters in a string. For example,length("abc")is3.x + y: the result of concatenatingxandy. For example,"abc" + "def"evaluates to"abcdef".matches(string, pattern): returnstrueif and only ifpatternoccurs instring, case-sensitive. For example,matches("def", "def")andmatches("abcdefefg", "*def*")both returntrue.substring(s, b, e): the substring of stringsstarting from indexb(inclusive) and ending at indexe( exclusive). For example,substring("abcdef", 0, 6)is"abcdef",substring("abcdef", 1, 3)is"bc"(empty string), andsubstring("abcdef", 1, 1)is"".prefix(s, n): the firstncharacters of strings. For example,prefix("abcdef", 3)is"abc",prefix("abcdef", 0)is""(empty string), andprefix("abcdef", 10)is"abcdef".suffix(s, n): the lastncharacters of strings. For example,suffix("abcdef", 3)is"def",suffix("abcdef", 0)is""(empty string), andsuffix("abcdef", 10)is"abcdef".toUpperCase(x)andtoLowerCase(x): respectively change all alphabetic characters in the string to upper- and lower-case. For example,toUpperCase("UpperCase")is"UPPERCASE"andtoLowerCase("LowerCase")is"lowercase".replace(text, target, replacement): replaces every occurrence oftargetintextwithreplacement. All three arguments must be strings. For example,replace("abc-def", "-", "_")is"abc_def",replace("abc-def", "-", "")is"abcdef"andreplace("abab", "a", "cd")is"cdbcdb".