LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Take an existing text file and modify values

Solved!
Go to solution

I’m looking to take an existing text file and modify certain values inside of it. Then save it to a new file, with all the same formatting as the original. The file format is not uniform and can change.

 

Basically the file is:

Random numbers and letters of unknown length for an unknown number of lines.

 

Label="Test_#"

Description

String

X=123

Y=456

Z=-789

20 lines of strings with numbers in them

 

Label="Test_#2"

Description

String

X=-1232

Y=4562

Z=7892

 

Then it repeats a set number of times.

 

I want to modify the X Y and Z = values for each Test_#.

 

I’ve managed to import the important values into a numeric array and I have a different array with values that will replace the existing ones. I’m having troubles replacing the existing ones. There are no zeros before or after the existing numbers so they are all different lengths.

 

If anyone has any sample code that does anything similar please post it. I’m sure someone has done something like this in the past. 

0 Kudos
Message 1 of 4
(2,721 Views)
Solution
Accepted by topic author markog

I would simply read the file as lines into a 1D array of strings (Read Text File with the function configured to read lines). Then you can search the array for the line Label="Test_#", which will give you a reference index for the X, Y, Z lines. You can then use Replace Array Subset to replace those lines, and then simply write out the new line. 

Message 2 of 4
(2,715 Views)

Replace the whole line!  Smiley Embarassed Thank you.

0 Kudos
Message 3 of 4
(2,711 Views)

I just thought I would throw this out there.  Can you make the .txt file tokenized?  This would make searching for specific parameters much easier.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 4 of 4
(2,683 Views)