SA-MP Forums Archive
hello, I would require to Indentify and Remove a line from a txt file, any ideas? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: hello, I would require to Indentify and Remove a line from a txt file, any ideas? (/showthread.php?tid=195801)



hello, I would require to Indentify and Remove a line from a txt file, any ideas? - DeadAhead - 03.12.2010

Okay so i would require to identify a line, then remove that specific line from the txt file?


Re: hello, I would require to Indentify and Remove a line from a txt file, any ideas? - DeadAhead - 04.12.2010

Bump'd proffesionaleh.


Re: hello, I would require to Indentify and Remove a line from a txt file, any ideas? - Jacob_Venturas - 04.12.2010

uhm, maybe use dini? or dubd


Re: hello, I would require to Indentify and Remove a line from a txt file, any ideas? - DeadAhead - 04.12.2010

Currently am trying Dutils and fopen e.t.c. Il see if i can get success there, dudb,nor dini dont have the functions i require.


Re: hello, I would require to Indentify and Remove a line from a txt file, any ideas? - Jochemd - 04.12.2010

Nop, it can't with dini, unsure about dudb.


Re: hello, I would require to Indentify and Remove a line from a txt file, any ideas? - dice7 - 04.12.2010

You can only use dini/dudb/etc if you actually have the file saved in their format

Anyways create a new file without the line you wanted and the rewrite the old file with the created one. Then delete the created one.
pawn Код:
new aLineFromTheFile[256];
new File:f = fopen("file.txt", io_read);
new File:temp = fopen("temp.txt", io_write);

while (fread(f, aLineFromTheFile))
{
    if (strcmp (aLineFromTheFile, "The line I want") == 0)
    {
        printf("This line won't get written in the temp file");
        continue;
    }
    fwrite(temp, aLineFromTheFile);
}
fclose(f);
fclose(temp);

//rewriting the original file with the temp one
f = fopen("file.txt", io_write);
temp = fopen("temp.txt", io_read);
while (fread(temp, aLineFromTheFile))
{
    fwrite(f, aLineFromTheFile);
}
Fremove("temp.txt");