Problem about nickname
#1

hello
today i was reading a code to take only the name in the nick (only nick with this format Name_Surname) and it work really grat with this code:

pawn Код:
new playername2[MAX_PLAYER_NAME];
    new playernamesplit[3][MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername2, sizeof(playername2));
    split(playername2, playernamesplit, '_');
so if the nick is Adam_Smith it will take only "Adam" part of the nick, i would know if is possibile take the other part (Smith part), so the part is after the "_"
thanks
Reply
#2

Use function like this
pawn Код:
chrfind(string[], chr, start = 0)
{
  while (string[start])
    if (string[start++] == chr)
      return start - 1;

  return -1;
}
to get position of "_", and use this position + 1 as string index

pawn Код:
new idx = chrfind(playername2, '_') + 1;
printf("%s", playername2[idx]);

Reply
#3

Quote:
Originally Posted by Nubotron
Use function like this
pawn Код:
chrfind(string[], chr, start = 0)
{
  while (string[start])
    if (string[start++] == chr)
      return start - 1;

  return -1;
}
to get position of "_", and use this position + 1 as string index

pawn Код:
new idx = chrfind(playername2, '_') + 1;
printf("%s", playername2[idx]);

can't understand very well this part "new idx = chrfind(playername2, '_') + 1"
what +1 stands for?

edit: i got it now , i'm a lil slow
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)