Example Code

Find and Replace Multiple Values from a Text File

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

 Overview

This example searches for an array of items and replaces each one with a corresponding term in another array.

 

Description

This example will prompt the user for a text file.  It will then search through that text file locating values specified by the "Terms to Replace" control.  As long as the "Replace all terms?" control is true each value found within the text file will be replaced with the value in the corresponding index in the "New Terms" control.  If the "New Terms" control is left blank the values will be deleted from the text file.  The program will then prompt the user to save a new text file with the changes that have been implemented.  It will also display the number or replacements made for each value and the resulting text for the text file.

  

Requirements

LabVIEW Full Development System 2012 or compatible

 

Steps to Implement or Execute Code

  1. Enter the path of the Input file and Output file
  2. Enter the Terms to Replace and New Terms elements
  3. Select whether the VI should Replace all Occurrences of Terms or not
  4. Run the VI, a new text file will be generated with the replace terms.

 

Additional Information or References

VI Block Diagram

3808.PNG

 

**This document has been updated to meet the current required format for the NI Code Exchange. **

 

 

Thanks!
Bob H
Applications Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.