LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I replace each instance of a character in a string of unknown length with a newline character?

Basically I'm trying to take the output of a GPIB device, which comes in the form of a long string of numbers separated by commas, into something that could be read by a spreadsheet and graphed quickly.

Additionally, for plotting, I'm going to need to associate another number with each number in the string (it will be a graph of gain vs. frequency, and the GPIB device only outputs the gain), so the finished file will contain 2 columns and an unknown number of rows. I'm sure this is an easy problem for anyone who is well versed in Labview. Unfortunately, I am not one of those people. Help would be much appreciated!
0 Kudos
Message 1 of 3
(3,088 Views)
To answer your first question directly, there is a function on the String palette called Search and Replace String. You input the string, the search string, and the Replace String. By default, the Replace All? input is false so wire a true constant to it. Also on the String palette is an end of line constant. However, there is also on the String palette, a function called Spreadsheet String to Array and on the file palette a function called Write to Spreadsheet file. The first takes a tab or comma separated string and creates either a 1D or 2D array as output. Items separated by the delimiter become different column items and an end of line would become a new row. The Write to Spreadsheet takes a 1D or 2D array as input and writes a tab or comma separate
d file. You might want to look at these functions and see if they'll save you some time and effort.

As to your second question, the XY Graph is what you want to use on your front panel. It requires that you create X and Y arrays and bundle them together. Any number of rows can be graphed. The graph does require that the inputs be numeric so you'll have to convert the strings first. Fract/Exp String to Number will accept a string array and convert to a numeric array.
Message 2 of 3
(3,088 Views)
Try the "Extract Numbers.vi" to extract the numbers into an array. You will find it in LabVIEW help under string examples. XY Graph is the appropriate control to use for your type of plot, again I'll refer you to Graph examples.
Message 3 of 3
(3,088 Views)