Example Code

Parse String Input for Comments and Commands

Code and Documents

Attachment

Overview

This VI is a good example of parsing an input string to take out comments in a script. When you are processing text inputs, whether from a script or a command line, this can be helpful.

Description

This VI takes data in multiple lines of text, separated by end of line characters.  It parses them and places comments into one array and commands in another.  In this case, we use the # to denote a comment, and leftover lines are interpreted as commands (see picture of front panel below).

This can be used in programs where scripts are parsed.  Similar algorithms are used by consoles of many video games to separate commands from chats.

Steps to Implement or Execute Code

  1. Download
  2. Type commands and comments into string control, separated by hitting the enter key
  3. Run to watch the program sort the lines of text into two arrays

Requirements

Software

LabVIEW 8.2 or later

Hardware

Just your computer

Front Panel

parse string front panel.png

VI Snippet

parse string input.png

**This document has been updated to meet the current required format for the NI Code Exchange. For more details visit this discussion thread**

Regards,
Dan King

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

Contributors