Strings - Manhunter07/MFL GitHub Wiki
See also: Type constructors#string
Strings are concatenated (ordered lists of) characters. All strings are Unicode-encoded and run on platform-default multi-byte chars. Strings can have any length and support all printable and non-printable characters. They are internally represented as null-terminated UTF-16 character string. Like numbers or references, strings belong to the group of core data types and can be directly written in source code.
Literals
String literals are static (unnamed) string constants. They are enclosed by double quotes (") and may contain any printable characters.
Special characters
- Double-quote characters can be inserted by an escape sequence using two double quotes after one another:
"". A string consisting of only a double quote would therefore require four contiguous double-quote characters in code (""""). - Non-printable characters cannot be notated in string literals, they require an expression to be inserted. They can be added by concatenation and using the
Charconstructor:"This is a" + Char(13) + Char(10) + "line break.".
Operators
See also: Operators#Strings
Unary
| Operator | Operation |
|---|---|
+ |
|
- |
Case inversion |
The positive prefix operator (+) does not perform any operation.
A case conversion (-) inverts the letter cases of all upper- and lower-case lette characters within the string. Characters within the range of A to Z will become their respective counterpart in the range of a to z and vice versa. Other characters are not be modified. Invoking this operation twice on any string reverts itself and returns the original string value.
Binary
| Operator | Right operand | Operation |
|---|---|---|
+ |
String | Concatenation |
* |
Integer number | Duplication |
/ |
String | Substring count |
% |
Number, string or array | Format |
? |
String | Comparison |
~= |
String | Text case-insensitive equality |
?= |
String | Text equality |
?: |
Type name | Type compatibility |
Type check
Like any other data type, strings support the type compatibility check operator (?:). It returns True on string types that support the character count and False on any other kinds of type.