| Using VISA.NET > Formatted I/O > Using Scanf > Scanf Format Specifier Syntax |
This section discusses the format specifier fields that may appear in the format strings passed to the Formatted I/O Scanf methods. The Scanf method formats data provided by input arguments. The data is created by parsing the input data using each format specifier in the format parameter to interpret the corresponding data from the instrument and place the result in the corresponding parameter argument. The data is interpreted as ASCII strings, IEEE 488.2 arbitrary blocks, and raw binary blocks.
For further details, see:
A Scanf format string may include zero to seven format specifiers, each of which provides information about how to parse the input and extract a value for one of the variable arguments to Scanf.
Format specifiers for Scanf are very similar to those for the VISA viScanf function, though there are some differences. For example, 'a', 'A', 'C', 'n', 'p', and 'S' are not supported in VISA.NET.
A basic format specifier always starts with a '%' (percent character) and ends with a format type, which indicates the data type of the value to be parsed. For example, "%d" is a format specifier that will read a signed integer as a sequence of decimal digits. If the integer is negative, it will be preceded by a minus sign.
A variety of optional modifiers may be added to the basic format specifier to provide a rich set of parsing options. The general syntax of a VISA.NET format specifier is:
"%[flags] [width] [,arraySize] [sizeModifier] type"
For example, "%+@3d" is a format specifier that will read a signed integer in scientific notation, with a plus sign if the integer is non-negative and a minus sign if it is negative. Note that some modifiers are not valid with some format types, and some modifiers have different meanings, depending on the type.
For each format specifier, there is one value argument that corresponds to the format specifier type, and there may be additional modifier arguments (indicated by a '#' in the specifier) that provide information about the format specifier's modifiers. In the argument list, the modifier arguments for a format specifier are elements in the inputs array argument. Scanf parses a value (from a value argument) using a format specifier that may need additional information from modifier arguments to be complete.
For example:
Scanf("[%-#s]", {10}, "John");
This call will read the string "John". The first (and, in this case, only) value of the inputs array, 10, is the width – the maximum number of characters to be read for this format specifier. If the input string in the formatted read buffer were longer than 10 characters, only 10 would be read.
![]() |
Not all combinations of modifiers and types are meaningful. For example, "%@QX" is invalid because of two ambiguities:
|