-
Notifications
You must be signed in to change notification settings - Fork 8
String
Brom Bresenham edited this page Jun 26, 2024
·
5 revisions
Rogue strings are always stored internally as UTF-8.
"double-quote literal string"
'single-quote literal string'
''two-quote literal string''
@|verbatim
|string
|...
$fileString("filepath")
- A
'single-quote literal string'
must have more than one character or else it will be treated as a Character instead of aString
. - Verbatim Strings include everything exactly as typed. Escape characters have no effect.
- A file string creates a literal string from a specified file at compile time. To dynamically load a string from a file at runtime, use
String(File("filepath"))
.
Formatted strings are a way of easily building strings containing a mix of literal characters and variable values. The syntax is:
"literal string format with $ markers" (arg1,...)
Each $
marker is replaced with the corresponding argument.
local x=3, y=4
println "($,$)" (x,y+2) # prints: (3,6)
println "The cost is $$." ('$',dollars)
# There is no escape for expressing a literal '$' in a formatted string;
# you must use a '$' as an argument or string concatenation.
- You cannot use a string variable as the format because the underlying code transformation happens at compile time, not runtime.
Sequence | ASCII | Description |
---|---|---|
\0 | 0 | Zero / end-of-string (EOS) |
\b | 8 | Backspace |
\e | 27 | Escape |
\f | 12 | Form Feed |
\n | 10 | Newline / end-of-line (EOL) |
\r | 13 | Carriage Return |
\t | 9 | Tab |
\v | 11 | Vertical Tab |
\/ | 47 | Forward Slash |
\? | 63 | Question Mark |
\' | 39 | Single Quote |
\\ | 92 | Backslash |
\" | 34 | Double Quote |
\xNN | 0..255 | 8-bit hexadecimal specification |
\uNNNN | 0..65535 | 16-bit hexadecimal specification |
\u[N..NNNNNN] | 0..(2^24-1) | 4-bit to 24-bit hexadecimal specification (\u[41] , \u[1f642] , ...) |