Owning Palette: String Functions
Requires: Base Development System
Formats string, path, enumerated type, time stamp, Boolean, or numeric data as text.
You can use the Format Into String function to convert a number into a string. To format data as text and write the text to a file, use the Format Into File function instead.
Add to the block diagram | Find on the palette |
format string specifies how you want the function to convert the input arguments into resulting string. Defaults match the data type of the input arguments. Right-click the function and select Edit Format String from the shortcut menu to create and edit the format string. Use special escape codes to insert non-displayable characters, the backslash, and the percent characters.
|
|||
initial string specifies the base string to which you can append any arguments to form the resulting string. | |||
error in describes error conditions that occur before this node runs. This input provides standard error in functionality. | |||
input 1..n specifies the input parameters you want the function to convert. This parameter accepts a string, path, enumerated type, time stamp, Boolean, or any numeric data type. For complex numeric data types, this function converts only the real component. You cannot use arrays and clusters with this function. You can specify up to 4,096 characters for each input.
If you specify a Boolean value for this parameter and %s as the format code, the Format Into String function outputs the value as TRUE or FALSE. If you specify a Boolean value for this parameter and any numeric format code, the Format Into String function outputs the appropriate version of 1 for TRUE and 0 for FALSE. For example, if you specify %f as the format code, the function outputs 1.00000. If you specify %d, the function outputs 1. |
|||
resulting string contains the concatenation of initial string and the formatted output. | |||
error out contains error information. This output provides standard error out functionality. |
To increase the number of parameters, right-click input 1 and select Add Parameter from the shortcut menu or resize the function.
Note If an error occurs, the error out cluster element source contains a string of the form Format Into String (arg n), where n is the first argument for which the error occurred. |
If you wire a block diagram constant string to format string, LabVIEW uses format string to determine the number of outputs and the data type of each output at compile time. If the data types you wire to the outputs do not match the data types determined by format string, you must change the output data types before the VI can run.
By default, this function uses the order of the inputs to populate the format specifiers, or percent codes in the Format String. However, you can use a number followed by a dollar sign ($) within a percent code to specify exactly which input to use for that percent code. For example, the percent code %3$d uses the third input regardless of how many percent codes appear before %3$d in the format string.
Refer to the following block diagram and table for an example of how to use format specifiers:
The following input combinations illustrate the effects of the $ specifier in the previous block diagram:
Input 1 | Input 2 | Format String | Return String | Comments |
---|---|---|---|---|
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. |
You can use other special characters besides the $ to configure how this function populates the percent codes in format string.
Refer to the Buffered Stream to Tab-Delimited Text File VI in the labview\examples\File IO\Spreadsheet\Tab-Delimited Data directory for an example of using the Format Into String function.