SA-MP Forums Archive
Replace name in a file .txt - 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: Replace name in a file .txt (/showthread.php?tid=214156)



Replace name in a file .txt - ombre - 20.01.2011

Hi,

I have in my GM a file "test.txt" within some names. This file is called in OnPlayerConnect


Alex_Green
John_Smith
.
.
.

I want to create a commande who replace a name with another.
My code is:

Код:
gpname = old name
tmp = new name
file = fopen("test.txt", io_readwrite);   // open the file, read and write
   	while(fread(file,openf,sizeof(openf)))   
        {
            if (strfind(openf, gpname, true) != -1)   search a name
 	     {
			strmid(gpname, tmp, 0, strlen(tmp), 255);   replace this name by a new name
		        format(string, 256, "%s",tmp);                 
   	     }
    	}
   	fwrite(file, string); //write
   	fclose(file);
Example I want to remplace John_Smith by Will_Black with this code it check John_Smith but dont delete this name just add Will_Black In the end.

I know my code don't replace but I don't know how to make.

Thank to help.


Re : Replace name in a file .txt - ombre - 20.01.2011

maybe strdel or Strins?