Repository navigation
Category Block Strings
Home › All Categories › Block Strings
dim as ustring query = """
select id, name
from users
where active = 1
"""
print queryquery holds three lines, select id, name, from users and where active = 1, joined by line feeds. The indentation the code needs is gone; the indentation the text has is kept.
A line ends a statement in tiko, so an ordinary string literal never crosses one. Without block strings, several lines of text mean one literal per line, glued with &, chr( 10 ) and a _ continuation on every line. SQL, JSON, HTML, shader source and usage text are the cases where that hurts most. A block string is the text as it would appear in a file, indented to match the code around it.
It opens with """ that ends its line: nothing but spaces or tabs may follow it. That condition is what lets every other run of quotes keep its ordinary meaning (see Other Quote Sequences).
It closes at the first line that starts, after spaces and tabs, with """. Anything after the closing """ is ordinary code, so the block can sit in the middle of an expression:
print Trim( """
padded
""" & " tail" )The closing line's indentation is the margin. It is removed from the start of every line in the body, byte for byte. A line indented further keeps the extra; a blank line is always fine, whatever whitespace it holds. A non-blank line that does not start with the margin is error TKO0208. A tab never counts as spaces, so a tab-indented line under a space-indented closer is an error, not a guess.
dim as ustring a = """
two spaces kept
here
""" ' margin: 4 spaces
dim as ustring b = """
all four kept
""" ' margin: noneLine breaks. The line break after the opening """ and the one before the closing line are not part of the value. Every line break inside it is a single line feed, chr( 10 ), whether the source file uses CRLF or LF. For a trailing line feed, leave an empty line before the closing line.
Quotes and backslashes need no escaping. " is just a character, and so is """ in the middle of a line; only a line that starts with """ closes the block. A backslash is an ordinary character, as it is in any plain tiko string.
Prefixes. !""" reads backslash escapes, exactly as !"..." does, after the margin is removed. A backslash at the very end of a line joins that line to the next with no line break. $""" is the same as """.
dim as ustring row = !"""
name\tvalue
one long line, \
continued
""" ' "name<TAB>value" LF "one long line, continued"A block string can go anywhere a string literal can: an initializer, a const, an argument, a #define. In a module's interface, or when a macro stringises it, it is written back as the equivalent one-line !"..." literal.
| Id | When |
|---|---|
TKO0207 |
No closing line before the end of the file. The rest of the file becomes the string. |
TKO0208 |
A non-blank line does not start with the closing line's indentation. |
tiko reads """ followed by the end of the line as the start of a block string. Every other spelling keeps its ordinary meaning: """abc""" is the five-character string "abc", and """" is one quote.
See Compatibility.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing