This topic is about literal constant numbers and strings that can be used in Quick Macros.
Integer numbers can be in 3 formats:
1. Decimal. Examples: 47, -2000000000.
2. Hexadecimal. Examples: 0x2F, 0x88ca6c00. Octal is not supported.
3. Character. Examples: 'a', '.', ' '. The value is its character code, which can be 1 to 255 in ANSI mode and 1 to 127 in Unicode mode.
Numbers 0 to 2147483647 are of type int. Numbers 2147483648 to 4294967295 are unsigned int. Bigger numbers are of type long. To change type can be used suffix letter I (int), U (unsigned int) or L (long). Example: 10L.
Non-integer numbers are those that contain either decimal point (.) or exponent (E followed by a 1-3 digit number), or both. Examples: 5.12, 0.975E-5, -2e10. Must begin with a digit. The exponent specifies the magnitude of the number as a power of 10. For example, 1.5E2 is 150, and 1.5E-1 is 0.15. The type is double. Also called "floating-point".
Strings are enclosed in double quotes (quotation marks). Example: "notepad.exe". Type - lpstr.
Such strings cannot contain literal newlines and double quotes. Instead use escape sequences:
Escape sequence | Is replaced with |
---|---|
[] | Line break (carriage return+linefeed) |
'' (two single quotes) | " (double quote) |
[digits] | Character whose character code is the number in [ ]. The number can be 1 to 255 in ANSI mode and 1 to 127 in Unicode mode. For example, [9] is replaced with tab. |
Example:
out "''name''[][65]" Output: "name" A
If you need literal [], to avoid replacing it to new line use [91]]. For '' use [39]'. For [digits] use [91]digits].
You can use the Text dialog to get properly escaped string. In the dialog you enter simple (nonescaped) text, and, when you click OK, it inserts escaped and enclosed string.
Escape sequences that are in a macro are replaced before the macro runs. Escape sequences are not replaced in text that your macro gets at run time (for example, from a file, clipboard, etc). If you need QM escape sequences at run time, use str.escape.
Some functions have own escape sequences. They are replaced at run time. For example, str.format and other functions that support formatting, str.timeformat, regular expression functions.
Multiline strings can be created using []. Example: "line1[]line2[]line3". Alternatively, you can place all text in other macro, and populate a str variable with text of that macro. Example: str s.getmacro("big string").
A multiline string also can be created as a block of comments that is assigned to a lpstr or str variable. Example:
lpstr s= multiline string out s
In such multiline strings, escape sequences are not replaced. For example, [] is not new line.
Make sure that there are no empty lines. An empty line terminates the multiline string, even if it is followed by more comments. To add new line characters to the end, add line containing just one space or semicolon.
QM 2.3.0. In the comments block, some or all lines can begin with tabs (before space). The tabs are removed. In previous versions, tabs are not allowed.
The variable must be in simplest form. For example, it can be s but cannot be t.s or a[i]. It must not be a member variable.
Use operator L to create Unicode UTF-16 constant strings. Example: L"String". However all characters must be in range 1-255 (in ANSI mode) or 1-127 (in Unicode mode).
QM 2.3.0. You can instead use operator @. It converts to UTF-16 at run time. Example: @"String". It also can be used with variables.
Add operator F before, and enclose variables in { }. Such string is not constant.
strVariable=F"text{variable1}text{variable2}"
strVariable= F text{variable1}text text{variable2}text
Or use string functions, for example format or from.
You can use def to define named constants.