Creating Text Files
- Updated2026-05-01
- 3 minute(s) read
Create and write text files by converting data to strings and then writing or formatting the output. Scan existing text files to extract data of other types.
To create a text file, do the following:
- Convert the data to string data.
- If needed for your application, format the string data.
- Write the text data to the file.
If needed for your application, you can also create a text file by scanning an existing file and processing the data.
-
To write data to a text file, convert the data to a string.
Use the functions on the String palette to convert your data to a string. For example, the VI in Figure 30. Converting Numeric Data to String does the following:
- Converts an array of randomly generated numbers to strings
- Writes the strings to a text file
Figure 30. Converting Numeric Data to String
-
To add text to a file you create, use the Write to Text File
function.
If you wire a file path to Write to Text File, rather than a refnum, Write to Text File automatically opens and closes the file.
Write to Text File does not format text. Most word processing applications that read text do not require formatted text. As a result, writing text to text files does not expressly require formatting.
Figure 31. Writing Unformatted Text to a File
-
If your application requires text files with specific formatting, use the available
functions to format string data.
For example, you can use the Format Into File function to accomplish two actions:
- Format multiple data types as text
- Write the formatted text to a file
The following VI acquires multiple data types and writes the data to a file.
Figure 32. Formatting and Writing Data to a Text File
In many cases, Format Into File can replace two actions: formatting the string with Format Into String function and then writing the resulting string with Write to Text File.
-
To scan text in a file for string, numeric, path, and Boolean values and then convert
the text into a data type, use the Scan From File function.
In many cases, Scan From File can replace two actions: reading data from a file with the Read from Binary File function or Read from Text File function and then scanning the resulting string with the Scan From String function.
Functions that format text include the format string input. Use format strings and format specifiers to define how to convert input arguments.
For more information on the functions that format strings and on format string, see the following resources:
- Formatting Strings
- Format Specifier Syntax
- Using Format Specifiers in Numeric Strings
Related Information
- Grouping Data with Strings
- Building the Block Diagram
- Block Diagram Objects
- Format Specifier Syntax
Understand LabVIEW format specifier syntax for format strings that format output or scan input.
- Formatting Strings
- Using Format Specifiers in Numeric Strings
- NI KnowledgeBase—Using VI Snippets to Store and Share Reusable Code Sections