| Using VISA.NET > Formatted I/O > Using Printf > Printf Format Specifier Syntax > Printf Modifiers |
The supported modifiers in the Printf format specifier are:
The width modifier is optional. It may be used with characters and strings (types c and s), integers (types d, i, o, u, x, and X), and real numbers (types e, E, f, g, and G). Width is not valid for IEEE 488.2 blocks (types b and B) or raw binary arrays (type y).
Width specifies the minimum width of the formatted value. The string is padded with spaces on the left if the '-' flag is not specified, and on the right if it is specified.
If an array is specified, width applies to each element individually.
If width is '*', then the value of width is read from an input argument. The argument precedes the precision and arraySize input arguments, if they are specified, and the value input argument. The width input argument may be a signed or unsigned positive integer.
![]() |
Do not use width values that are not signed or unsigned positive integers (for example, zero, fractions, or negative numbers).The results are undefined and Printf may throw an exception. Since Printf does not always throw an exception when width is invalid, it is important that width always be a signed or unsigned positive integer. |
The precision modifier is the '.' (period) character followed by a precision argument.
The precision modifier is optional. It may be used with characters and strings (types c and s), integers (types d, i, o, u, x, and X), and real numbers (types e, E, f, g, and G). Precision is not valid for IEEE 488.2 blocks (types b and B) or raw binary arrays (type y).
For characters (type c), the precision modifier is ignored.
For strings (type s), precision is the maximum number of characters printed.
For integers (types d, i, o, u, x, and X), precision is the maximum width of the printed value. If the full formatted value is longer than precision characters, the first precision characters are printed and the rest are discarded.
For some real numbers (types e, E, and f), precision is the number of digits after the decimal point. For other real numbers (types g and G), precision is the number of significant digits.
If an array is specified, the precision modifier applies to each element individually.
If precision is '*', then the value of precision is read from an input argument. The argument precedes the arraySize input argument, if there is one, and the value input argument. The precision input argument may be a signed or unsigned positive integer. Do not use other values (such as zero, fractions, or negative numbers): the results are undefined and Printf may throw an exception.
![]() |
Do not use precision values that are not signed or unsigned positive integers (such as zero, fractions, or negative numbers). For such values, the results are undefined, and Printf may throw an exception. Since Printf does not always throw an exception when precision is invalid, it is important that precision always be a signed or unsigned positive integer. |
The array modifier is the ',' (comma) character followed by an optional arraySize argument. It indicates an array of numbers, optionally followed by arraySize - the number of elements to be formatted. You must include arraySize only if the number of elements to be printed is less than the number of elements in the input array argument.
The array size modifier is optional. It may be used with integers (types d, i, o, u, x, and X), and real numbers (types e, E, f, g, and G). Array size is not valid for characters (type c), strings (type s), IEEE 488.2 blocks (types b and B) ,or raw binary arrays (type y).
Arrays indicated by the ',' modifier are formatted as comma-separated lists, with each element formatted according to the format specifier.
The array size is determined as follows:
![]() |
Do not use arraySize values that are not signed or unsigned positive integers (such as zero, fractions, negative numbers). For such values, the results are undefined, and Printf may throw an exception. Since Printf does not always throw an exception when arraySize is invalid, it is important that arraySize always be a signed or unsigned positive integer. |
Size modifiers indicate the size of the data to be formatted.
When formatting numbers as ASCII strings, VISA.NET (unlike VISA or the ANSI standard version of printf), does not need size modifiers to determine the size of the value argument. As a result, VISA.NET ignores size modifiers when formatting numbers as ASCII strings.
Size modifiers are invalid for characters and strings.
Size modifiers are required when formatting IEEE 488.2 arbitrary blocks and raw binary arrays. In these cases, the type of the array argument to Printf that corresponds to the format specifier must match the size modifier. For example, if the format specifier is "%ly", the corresponding argument must be an array of 32-bit integers.
|
Modifier |
Applicable Types |
Description |
|---|---|---|
|
b (default) |
b, B, y |
Array elements are interpreted as 8-bit integers. |
|
h |
b, B, y |
Array elements are interpreted as 16-bit integers. |
|
l (lowercase L) |
b, B, y |
Array elements are interpreted as 32-bit integers. |
|
ll (lowercase LL) |
y |
Array elements are interpreted as 64-bit integers. |
|
z |
b, B |
Array elements are interpreted as 32-bit reals. |
|
Z |
b, B |
Array elements are interpreted as 64-bit reals. |
|
I, I32, I64 (uppercase i, i32, i64) |
N/A |
These ANSI-defined size modifiers are always ignored by VISA.NET. |
![]() |
Do not use size modifiers not listed in the above table, and do not use size modifiers with format types that are not listed as applicable types for the modifier. For unlisted modifiers and types, the results are undefined, and Printf may throw an exception. Since Printf does not always throw an exception when the size modifier is invalid, it is important that size modifiers always be used with applicable types as indicated in the above table. |