Print format
Purpose: Outputs formatted data.
print-format <format> , <variable> [ , <variable> ]... \
[ to-error ] \
[ to <string> ] [ url-encode | web-encode ]
Copied!
print-format will format a string according to the <format> string and a list of <variable>s and then outputs the result. By default, the output is not encoded (meaning a string is output exactly as it is, and the client may interpret such text in any way it sees fit). If "web-encode" clause is used, then the output is web-encoded (or HTML-encoded);this means such output is suited for use in web pages - meaning any HTML-markup will be properly encoded. If "url-encode" clause is used, then the output is URL-encoded; this means such output is suited for use in URL parameters.
<format> string must be a literal. Variables must follow <format> separated by commas in the same order as placeholders. If you use any placeholders other than specified below, or the type of variables you use do not match the type of a corresponding placeholder in <format>, your program will error out. You can use the following placeholders in <format> (see trace-run for an example of usage):
- %s for a string
- %c for a number displayed as a character,
- %<number>s for a string output with a width of at least <number> (any excess filled with spaces to the left),
- %ld for a number (use "lo" for displaying in octal notation and "lx" for hexadecimal notation).
- %<number>ld for a number output with a width of at least <number> (any excess filled with spaces to the left). Use "lo" for displaying in octal notation and "lx" for hexadecimal notation.
If "to-error" clause is used, the output is sent to "stderr", or standard output stream.
If "to" clause is used, then the output of print-format is stored into <string>.
To output data (the string output is "the number is 20"):
print-format "%s is %d", "the number", 20
Copied!
Create a query text string by means of write-string statement:
/ Construct the run-time text of dynamic SQL
write-string qry_txt
@select * from <<print-format "%s where id="%ld", table_name, id_num>>
end-write-string
Copied!
This example of web encoding displayes text containing HTML tags without them being rendered in the browser:
print-format "We use %s markup", "<hr/>" web-encode
Copied!
Here's an example of URL encoding. It creates a URL based on arbitrary strings used as URL parameters - for instance space would be encoded as "%20" in the final output:
@<a href='<<print-path "/update">>?val=<<print-format "Purchased %s for %ld dollars", piece_desc, price url-encode>>'>Log transaction</a>
Copied!
Output
finish-output
flush-output
output-statement
print-format
print-out
print-path
See all
documentation
Copyright (c) 2019-2025 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.