Remove string from a file.
#1

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
Reply
#2

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");
Reply
#3

Big thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)