12-30-2011 09:59 AM
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.
Solved! Go to Solution.
12-30-2011 10:18 AM - edited 12-30-2011 10:19 AM
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.
12-30-2011 10:51 AM
Replace the whole line!
Thank you.
12-31-2011 06:48 PM
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.