split or for?
#1

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

Second way is better and faster i think.
Reply
#3

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)