PDA

View Full Version : Removing line from text file??


rado
03-06-2006, 04:01 PM
I'm new in AutoPlayMedia Studio6, so if somebody would like to help me how can I remove one specific line from the text file. I now first 10 characters from specific line.
Regards.

TJS
03-06-2006, 04:11 PM
This should get you started... you'll probably want to add some error checking after the text file reads and writes.

-- Declare the location of your text file and the sting you are looking for
g_MyTextFile = "C:\\mytextfile.txt"
g_SearchString = "abcdefg"

-- Setup an empty table to hold the contents of your text file
t_TextFile = {};

-- Read the contents of your text file to the table (See help file for more info)
t_TextFile = TextFile.ReadToTable(g_MyTextFile);

-- Step through each line in the table looking for your culprit and del any that match
local index;
local line;
for index, line in t_TextFile do
if String.Find(line, g_SearchString, 1, true) == 1 then
Table.Remove(t_TextFile, index);
end
end

-- Write the results back to your text file
TextFile.WriteFromTable(g_MyTextFile, t_TextFile, false);

rado
03-06-2006, 10:10 PM
Thank you very much. I think that I now understand how it works.
Rado