Inserts input data into specified locations in a string and formats that data according to your specifications.
A string that includes a format specifier for each input along with any additional text that you want to appear in the output. A format specifier is a series of characters, initiated by a %, that indicates how to convert the associated input argument into text.
Each format specifier uses the following general syntax:
% modifiers specifier
This input accepts a maximum of 255 characters.
Specifiers
Specifier | Definition |
---|---|
x | hexadecimal integer |
o | octal integer |
b | binary integer |
d | signed decimal integer |
u | unsigned decimal integer |
f | floating-point number with fractional format |
e | floating-point number in scientific notation |
g | floating-point number in either fractional format (f) or scientific notation (e) depending on the exponent of the number:
|
^e or ^g | floating-point number in engineering notation |
p | floating-point number in SI notation |
T | absolute time, most commonly used to interpret timestamp data |
t | relative time, most commonly used to interpret numeric data as elapsed seconds |
Modifiers for Numeric Specifiers (x, o, b, d, u, f, e, g, p)
If you use multiple modifiers, they must appear in the following order:
%[-][+][#][0][width][.precision || _significantDigits]specifier
Modifiers for Time Specifiers (t, T)
Use the following syntax to specify which parts of a time you want to format:
%[-]width <time specifier codes>t
Modifier | Definition |
---|---|
- |
Left justifies the output within its width. If the node inserts spaces to create the specified width, the spaces appear to the right of the value. |
width |
A number specifying the minimum number of characters that the node uses in the output. If the value requires fewer characters, the node pads the output with spaces to meet this width. This width is not a maximum width. The node uses as many characters as necessary to output the value without truncating it. If width is missing or 0, the output uses only as many characters as necessary to contain the formatted value. |
Modifiers for the String Specifier (s)
Use the following syntax to format a string:
%[-]width s
Modifier | Definition |
---|---|
- |
Left justifies the output within its width. If the node inserts spaces to create the specified width, the spaces appear to the right of the value. |
width |
A number specifying the minimum number of characters that the node uses in the output. If the value requires fewer characters, the node pads the output with spaces to meet this width. This width is not a maximum width. The node uses as many characters as necessary to output the value without truncating it. If width is missing or 0, the output uses only as many characters as necessary to contain the formatted value. |
Modifier for Reordering Inputs
Modifier | Definition |
---|---|
number$ | Explicitly specifies which input to use for the containing format specifier. This modifier overrides the default input with
the input specified by
number.
When you use this modifier, the subsequent format specifiers become associated with the inputs that follow the input specified by number. To avoid confusion, National Instruments recommends using this modifier in all format specifiers if you use it in one. |
Modifiers for Overriding Units
Syntax for Including Literal Characters in a Format String
Most characters outside of a format specifier appear literally in the output. However, you must use special syntax for the following special characters:
Syntax | Definition |
---|---|
\00 - \FF | Hex value of an 8-bit character; must be uppercase |
\b | Backspace (ASCII BS, equivalent to \08) |
\f | Form feed (ASCII FF, equivalent to \0C) |
\n | Linefeed (ASCII LF, equivalent to \0A). Format into File automatically converts this code into the platform-dependent end-of-line character. |
\r | Carriage return (ASCII CR, equivalent to \0D) |
\t | Tab (ASCII HT, equivalent to \09) |
\s | Space (equivalent to \20) |
\\ | Backslash (ASCII \, equivalent to \5C) |
%% | Percent sign |
Default: A string containing the default format specifier for the data type of each input, separated by spaces
A string to which this node appends format string in order to form the resulting string.
Error conditions that occur before this node runs.
The node responds to this input according to standard error behavior.
Standard Error Behavior
Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.
Default: No error
Input data to be converted to text, as determined by the corresponding format specifier in format string. This node assigns inputs to format specifiers sequentially, such that the first format specifier formats input 1, the second format specifier formats input 2, and so on.
Each input can be a string, path, Boolean, enumerated type, timestamp, or numeric value. You cannot use arrays and clusters with this node.
The number of input parameters must match the number of format specifiers in format string. Furthermore, the data type of each input must be compatible with the associated format specifier. Otherwise, the node returns an error.
The concatenation of initial string and the formatted output.
Error information.
The node produces this output according to standard error behavior.
Standard Error Behavior
Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.
These errors occur when you wire a string to format string that contains a different number of format specifiers than there are input parameters. To fix this mismatch, either resize the node to display the same number of inputs as format specifiers, or modify the number of format specifiers in format string to match the number of inputs.
This error occurs when you wire a string to format string that contains at least one format specifier whose data type specifier is incompatible with the data type of the corresponding input parameter. The text of the error specifies which parameter caused the mismatch. To fix this mismatch, you must change either the data type specifier in the relevant format specifier or wire a compatible data type to the relevant input.
Syntax element(s) | input | format string | output | Comments |
---|---|---|---|---|
%g # modifier |
12.00 | %#g | 12 |
The node interprets the g specifier as f because the exponent of the input in scientific notation (1) is less than the default precision of 6. The # modifier omits the six zeroes that would normally appear after the decimal based on the default precision of 6. |
12000000 | %#g | 1.2E+7 |
The node interprets the g specifier as e because the exponent of the input in scientific notation (7) is greater than the default precision of 6. The # modifier omits the six zeroes that would normally appear after the decimal based on the default precision of 6. |
|
%d literal % |
12.67 | score= %d%% | score= 13% |
Because the d specifier produces an integer output, the input is rounded to the nearest integer. %% produces a literal %. |
width precision literal text |
12.67 | Temp: %5.1f | Temp: 12.7 | The 5 in the format specifier specifies a width of 5, and the 1 specifies the precision, or number of digits to the right of the decimal. |
overriding units | 12.67 N | %5.3f | 12.670 N | The format specifier does not include the unit override syntax ({ }), so the output contains the original unit. |
12.67 N | %5.3{mN}f | 12670.000 mN | {mN} is compatible with N, so the node makes the appropriate conversion. | |
12.67 N | %5.3{kg}f | 12.670 ?kg | {kg} is not compatible with N, so no conversion occurs, and the output includes a ?. | |
converting to engineering notation | 12.67 | %.3e | 1.267E+1 | Without the ^ modifier, the e specifier places the decimal to the right of the most significant digit. |
12.67 | %^.3e | 12.670E+0 | Adding ^ to the format specifier produces an output in which the exponent is a multiple of 3. This determines the placement of the decimal. | |
%p precision vs. significant digits |
12000000 | %.2p | 120.00M |
Using the decimal point as part of the format specifier impacts the precision, or number of digits after the decimal point in the output. mega (10^6) is the closest SI prefix to the input value, so the output represents the value as M. |
12000000 | %_2p | 120M |
Using the _ modifier specifies the number of significant digits in the output. mega (10^6) is the closest SI prefix to the input value, so the output represents the value as M. |
|
non-decimal numbers (%x, %o, %b) padding with zeroes |
12 | %02x | 0C | The 2 in the format specifier causes the output to contain at least 2 characters. The 0 in the format specifier causes 0's to appear as the extra characters required to meet the width. |
12 | %06o | 000014 | The 6 in the format specifier causes the output to contain at least 6 characters. The 0 in the format specifier causes 0's to appear as the extra characters required to meet the width. | |
12 | %b | 1100 | This format specifier omits the width, so the output contains only enough characters to represent the input value as a binary number. | |
%s multiple format specifiers |
Smith John |
Name: %s, %s. | Name: Smith, John. | The format string must contain two format specifiers because the node accepts two inputs. |
variable order |
first second |
%s %s | first second | format string does not use the $ specifier, so the function populates the percent codes in input order. |
first second |
%2$s %1$s | second first | format string uses the $ specifier to display the inputs in a different order than their input order. | |
first second |
%1$s %1$s %1$s | first first first | format string uses the $ specifier to display the first input multiple times and ignore the second input. | |
first second |
%2$s %s | error | The first format specifier uses the second input, which causes the next format specifier to want to use a third input. Because there are only two inputs, the node returns an error. |
Where This Node Can Run:
Desktop OS: Windows
FPGA: All devices (only within an optimized FPGA VI)
Web Server: Supported in VIs that run in a web application