Strings with variables

QM 2.3.2.

 

Use operator F to insert variables and other expressions in strings. Enclose variables in { }.

 

F"text{variable1}text{variable2}"

 

To define custom format, after variable insert format field with two %.

 

F"text{variable1%%-20s}text"

 

Default format depends on variable type:

int, word, byte, pointers %i. For 0x{variable} uses %X instead.
str, lpstr %s
long %I64i. For 0x{variable} uses I64X instead.
double %.15G
Other types Not supported.

 

Variables also can be used in multiline strings. Example:

 

str s=
F
 text{variable1}text
 text{variable2}text

 

Escape sequences are replaced only in text parts of quoted strings. As escape sequence for { can be used {{. The {{ escape sequence also can be used in multiline strings.

 

QM 2.3.4. In variable fields can be used strings enclosed in ` (grave accent). In multiline strings use " instead.

 

Strings with variables cannot be used in strings that must be constant, such as dll names and case strings.

 

Strings with variables, when used for macro names and file names, prevent automatic adding these macros and files to exe.

 

Examples

int i=50
str s="stringvar"
double d=3.1415926535897932384626433832795
str sv=F"variables: i={i}, s=''{s}'', d={d%%.5G}, sum={i+d}, function={_s.from(`string` i)}"
out sv ;;variables: i=50, s="stringvar", d=3.1416, sum=53.1415926535898, function=string50

 also can use F"string" with key
key TT F"variables: 0x{i} {s%%20s} {d}" Y

 

See also: str.format, string constants and escape sequences, str.escape.