LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

deleting a portion of a text file programmatically

Solved!
Go to solution

Hi there,

 

I have a problem where I am continually rewriting data to a line in a text file through a series of questions.  The user has the ability to move back and forth through a sequence of steps and the line of output is written after each step is finished (this is done as a full safe in case they stop the program before completing all of the steps).  Occasionally the final line of data ends up being shorter than one of the previous times the data was written to that line resulting in junk at the end of the line.  I am wondering if there is a way to easily erase the line written previously before the next line is written.  This line is being appended to a file containing other lines so I can't simply overwrite the whole file - I have an initial offset value that is the start of the new line.

 

Hopefully this makes sense!


Thank-you for any help you can offer.

 

0 Kudos
Message 1 of 6
(2,513 Views)

Without seeing code, it is hard to tell, but it seems you use a fixed size line for each entry. Just pad the string with the correct number of spaces before writing.

0 Kudos
Message 2 of 6
(2,508 Views)

I had thought about this - but I am using array to spreadsheet string before writing so I wasn't sure how to do this and I thought the other method might be easier.  I will play around with padding before the return and see if I can figure it out!

Thank-you!

0 Kudos
Message 3 of 6
(2,494 Views)
Solution
Accepted by PA_UW

After "array to spreadsheet string", you have a plain string that you could e.g. pad/truncate to a fixed length as follows.

 

padstring.png

 

0 Kudos
Message 4 of 6
(2,486 Views)

Personally, I would just keep all lines in memory and rewrite the file after each change.

0 Kudos
Message 5 of 6
(2,485 Views)

Thank-you!  This worked really well and solved my problem.  

 

Thanks for your time - I appreciate it!

0 Kudos
Message 6 of 6
(2,454 Views)