split or for? - 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: split or for? (
/showthread.php?tid=130366)
split or for? -
ErF - 26.02.2010
Hi. I deleting "_" from nick, and I question what is more optimal for the server. I mean load.
First way:
Код:
new name[MAX_PLAYER_NAME];
new name_split[3][MAX_PLAYER_NAME];
new string[128];
GetPlayerName(playerid,name,sizeof(name));
split(name,name_split,'_');
format(string,sizeof(string),"Hi %s %s",name_split[0],name_split[1]);
SendClientMessage(playerid,some_color,string);
second way:
Код:
stock SomeFunction(name[])
{
for(new i = 0; name[i] != 0; i++)
if(name[i] == '_') name[i] = ' ';
}
new name[MAX_PLAYER_NAME];
new string[128];
GetPlayerName(playerid,name,sizeof(name));
SomeFunction(name);
format(string,sizeof(string),"Hi %s",name);
SendClientMessage(playerid,some_color,string);
Re: split or for? -
Jefff - 26.02.2010
Second way is better and faster i think.
Re: split or for? -
dice7 - 26.02.2010
Fastest
pawn Код:
new name[MAX_PLAYER_NAME];
new string[128];
GetPlayerName(playerid,name,sizeof(name));
new pos = strfind(name, "_");
if(pos != -1) name[pos] = ' ';
format(string,sizeof(string),"Hi %s",name);
SendClientMessage(playerid,some_color,string);
https://sampwiki.blast.hk/wiki/Strfind