Strings
Strings are immutable, double-quoted only (there's no single-quote string syntax), and can be indexed but not written to.
Literals & escapes
Falx recognises these escape sequences inside a double-quoted string - anything else after a backslash is a lexer error:
| Escape | Meaning |
|---|---|
\n | Newline |
\t | Tab |
\r | Carriage return |
\f | Form feed |
\b | Backspace |
\" | Literal double quote |
\\ | Literal backslash |
A literal, unescaped newline is also allowed directly inside a string (the string simply spans multiple lines):
let block = "line one
line two";
Indexing
Reading s[i] returns a one-character string; there's no separate "character" type. Writing to an index raises a runtime error, since strings are immutable:
let s = "Hello";
output(s[0]); // "H"
s[0] = "h"; // runtime error: 'string' is not indexable (for assignment)
length
output("Hello".length); // 5 - a property, not a method
Concatenation
+ on a string accepts another string, a number, or a boolean on the right-hand side, converting it to text - see Arithmetic.
output("Score: " + 42); // "Score: 42"
output("Done: " + true); // "Done: true"
Methods
Uppercases the string.
Lowercases the string.
Strips leading and trailing whitespace.
Whether needle occurs anywhere in the string.
Prefix/suffix checks.
Replaces every occurrence of search with replacement. Returns a new string - the original is untouched, since strings are immutable.
Splits on every occurrence of separator, returning an array of strings.
Parses the string as an integer. Raises a runtime error if it isn't a valid integer literal.
Parses the string as a float. Raises a runtime error if it isn't a valid numeric literal.
let s = "Hello, World!";
output(s.toUpper()); // HELLO, WORLD!
output(s.replace("World", "Falx")); // Hello, Falx!
output("a,b,c".split(",")); // ["a","b","c"]
output("42".toInt() + 1); // 43
Truthiness recap
A string converts to true only if it is exactly "true" (case-insensitive) - see the full explanation on Truthiness before using a string as a while or &&/|| condition.