[HELP] Player name
#1

hi

if player has a name in format Firstname_Lastname, how to extract only "Firstname" into another string? (without "_Lastname")

I want to make something like this: "Welcome back, Firstname", or "Welcome back, Firstname Lastname" (without "_").
how to do this? (if length of "Firstname" and "Lastname" and all player name is unknown)
Reply
#2

Use strmid:

pawn Код:
new pName[MAX_PLAYER_NAME], firstname[MAX_PLAYER_NAME], pos = -1;
GetPlayerName(playerid, pName, sizeof pName);
for(new c; c < MAX_PLAYER_NAME; c++)
{
  if(pName[c] == '_')
  {
    pos = c;
    break;
  }
}
strmid(firstname, pName, 0, pos);
Untested and roughly coded, I don't know if this works.
Reply
#3

It works, thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)