Prints a formatted expression to the results file.
Printf (sFormat, aArgs, ...)
Variable | Description |
---|---|
sFormat | The format to use. STRING. |
aArgs | Any number of arguments to print. ANYTYPE. |
Printf prints a formatted value to the results file.
%s (if the argument that follows is a string)
%d (if the argument that follows is an integer)
%o (if the argument that follows is an integer you want formatted in octal format)
%x (if the argument that follows is an integer you want formatted in hexadecimal format)
%f (if the argument that follows is a real number)
Printf("%*s", 5, "abc") // Prints __abc (the underscores represent spaces)
By default, the output is right-justified. A negative width causes left-justification.
For real numbers, you can also specify a second number, which is the precision of the output, in the form width.precision. You can use an asterisk as the precision to read the precision from the argument list.
Printf ("%s\\%s", sMyString, sMyString) // Prints abc\abc
Similarly, to output a percent sign (%), specify two percent signs in the format string.
[-] testcase PrintfExample () [ ] STRING sMyString = "abc" [ ] INTEGER iMyInt = 123 [ ] NUMBER nMyReal = 45.7 [ ] Printf ("%s", sMyString) // prints abc [ ] Printf ("%4d", iMyInt) // prints 123 [ ] Printf ("%4.2f", nMyReal) // prints 45.70 [ ] Printf ("%s%d", sMyString, iMyInt) // prints abc123 [ ] Printf ("%-4s%d", sMyString, iMyInt) // prints abc 123