| Using VISA.NET > Formatted I/O > Using Printf > Printf Format Specifier Syntax > Printf Flags |
Flags are optional characters or strings within a Printf format specifier that control justification of output and printing of signs, blanks (spaces), decimal points, and octal and hexadecimal prefixes. If present, flags immediately follow the '%' character that begins the format specifier. More than one flag can appear in a format specification.
![]() |
Do not use format specifiers that include an invalid flag, an invalid combination of flags, or flags that are out of order. The results of such format specifiers are undefined, and they may cause Printf to throw an exception or return arbitrary results. Note that since Printf does not always throw an exception in these cases, it is important to read and follow these rules, including the ones in the table, carefully. |
VISA.NET recognizes several ANSI-defined flags (space, '+', '0', '-', and '#') and several VISA-specific flags that support IEEE 488.2 formatting ('@1', '@2', '@3', '@H', '@Q', and '@B'). The following general rules, along with the specific rules in shown in the table below, determine what combinations of flags are valid in a format specifier.
Additional, more specific rules are also noted in the table below.
|
Flag |
Applicable Types |
Description |
|---|---|---|
|
'-' |
c,s |
Left-aligns the formatted string within the given field width. Note that '-' is only valid if the width is specified. If the '-' flag is not included, the formatted string is right-aligned within the given field width. |
|
' ' (space) |
d,i,o,u,x,X |
Prefixes the output value with a space if the output value is signed and positive. If the format specifier includes both a space flag and a '+' flag, the space flag is ignored. The space flag is ignored if the specifier also includes one of the IEEE '@H', '@Q', or '@B' flags. |
|
'0' (zero) |
d,i,o,u,x,X |
Pads the output value with the '0' character. The '0' flag is ignored if the width is not specified, or if the specifier also includes the '-' flag or one of the '@H', '@Q', or '@B' flags. |
|
'+' |
d,i,o,u,x,X |
Prefixes the output value(s) with a sign (+ or –). If the '+' flag is not included, the sign is only printed if the integer is negative. The '+' flag is ignored if the specifier also includes one of the '@H', '@Q', or '@B' flags. |
|
'#' |
o,x,X |
This flag is not currently recognized in VISA.NET, but may be added at a future date. |
|
'Q', 'q' |
s |
Encloses strings in double ('Q') or single ('q') quotes. For string arrays, encloses individual elements in double or single quotes. Since whitespace affects the way that string arrays are parsed, the use of quotes is required to remove ambiguity about the meaning of a comma-separated string array where the elements of the array could contain whitespace. |
|
'@1' |
d,i,u |
Formats the output value(s) in IEEE 488.2 NR1 format. This is the default format for format types d, i, and u. Real types are truncated before formatting. |
|
'@2' |
d, i, u |
Formats the output value(s) in IEEE 488.2 NR2 format. This is the default format for format type f. |
|
'@3' |
d,i,u |
Formats the output value(s) in IEEE 488.2 NR3 format. This is the default format for format type E. |
|
'@H' |
d,i,u,x,X |
Formats the output value(s) in IEEE 488.2 <HEXADECIMAL_NUMERIC_RESPONSE_DATA> format. Real types are truncated before formatting. |
|
'@Q' |
d,i,o,u |
Formats the output value(s) in IEEE 488.2 <OCTAL_NUMERIC_RESPONSE_DATA> format. Real types are truncated before formatting. |
|
'@B' |
d,i,o,u,x,X |
Formats the output value(s) in IEEE 488.2 <BINARY_NUMERIC_RESPONSE_DATA> format. Real types are truncated before formatting. |