Remove string from a file. - 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: Remove string from a file. (
/showthread.php?tid=162923)
Remove a string from a file. -
Butilka - 25.07.2010
Does anybody know how to remove a string from file?
For example:
I got a file text.ini and there are such lines
Код:
25|7|2010|127.0.0.1
25|7|2010|127.0.0.2
25|7|2010|127.0.0.3
25|7|2010|127.0.0.4
A string containing the IP 127.0.0.3 should be removed and file should be saved
Код:
25|7|2010|127.0.0.1
25|7|2010|127.0.0.2
25|7|2010|127.0.0.4
Re: Remove string from a file. -
Jefff - 25.07.2010
pawn Код:
stock fdeleteline(filename[], removed[])
{
new string[64], str[32], File:handle, File:ftmp;
handle = fopen(filename,io_read);
format(str,sizeof(str),"%s.part",filename);
ftmp = fopen(str,io_write);
while(fread(handle,string))
if(strfind(string,removed) == -1)
fwrite(ftmp,string);
fclose(handle);
fclose(ftmp);
handle = fopen(filename,io_write);
ftmp = fopen(str,io_read);
while(fread(ftmp,string))
fwrite(handle,string);
fclose(handle);
fclose(ftmp);
return fremove(str);
}
usage
pawn Код:
fdeleteline("text.ini", "127.0.0.3");
Re: Remove string from a file. -
Butilka - 25.07.2010
Big thanks!