Replacing "_" with an space in a string
#6

pawn Код:
stock GetPlayerFirstName(playerid)
{
    new
        namestring[2][MAX_PLAYER_NAME],
        name[MAX_PLAYER_NAME];

    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    split(name, namestring, '_');
    return namestring[0];
}

stock GetPlayerLastName(playerid)
{
    new
        namestring[2][MAX_PLAYER_NAME],
        name[MAX_PLAYER_NAME];

    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    split(name, namestring, '_');
    return namestring[1];
}
stock split(const strsrc[], strdest[][], delimiter)
{
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc)){
        if(strsrc[i]==delimiter || i==strlen(strsrc)){
            len = strmid(strdest[aNum], strsrc, li, i, 128);
            strdest[aNum][len] = 0;
            li = i+1;
            aNum++;
        }
        i++;
    }
    return 1;
}
USAGE: in the format() function, create two defenitions: %s %s, then match the first one with GetPlayerFirstName, and the second one with GetPlayerLastName, that way, you have removed the underscovre (_) with a space.
Reply


Messages In This Thread
Replacing "_" with an space in a string - by phillip875 - 18.08.2012, 19:13
Re: Replacing "_" with an space in a string - by ReVo_ - 18.08.2012, 19:15
Re: Replacing "_" with an space in a string - by phillip875 - 18.08.2012, 19:21
Re: Replacing "_" with an space in a string - by aintaro - 18.08.2012, 19:23
Re: Replacing "_" with an space in a string - by phillip875 - 18.08.2012, 19:27
Re: Replacing "_" with an space in a string - by Sandiel - 18.08.2012, 19:34
Re: Replacing "_" with an space in a string - by ReVo_ - 18.08.2012, 19:43
Re: Replacing "_" with an space in a string - by Edvin - 18.08.2012, 19:48
Re: Replacing "_" with an space in a string - by phillip875 - 18.08.2012, 19:49

Forum Jump:


Users browsing this thread: 1 Guest(s)