Author Topic: Editting lines with FileObjects..  (Read 1093 times)

Is it possible to edit specific lines from a .txt, such as deleting certain lines? If so, how would this be done?

Yes. The easiest way would probably be using a form of an array.

Construct an array, remove the line, then write again, ignoring lines that are blank.

%f = new FileObject()
%f.openfileforread(blah);
%i = 0;
While(!iseof(%f))
{
%f.line[%i] = %f.readline();
%i++
}
%f.close();

%f.line[4] = "REDACTED";
%f.openforwrite(blah);

For(%j = 0; %j < %i; %j++)
{
If(%f.line[%j] !$= "REDACTED")
   %f.writeline(%f.line[%j]);
}
%f.close(); %f.delete();

forgeted something up, I'm sure. I blame the phone in advance.
« Last Edit: December 20, 2012, 02:49:15 AM by Lugnut »

Could you write out an example? And would I need to use a script object?

Edit: Thankyou..
« Last Edit: December 20, 2012, 02:49:15 AM by Honorabl3 »

Yeah I did.
No, just make the array on the file object.

Be careful to not delete the FO before rewriting the file.

Will keep that in mind, thanks.