Replacing "_" with an space in a string -
phillip875 - 18.08.2012
Basically, I'm trying to make a function based off GetPlayerName, but to remove the "_" and replace it with a space.
pawn Код:
stock GetPlayerRoleplayName(playerid)
{
new playa[MAX_PLAYER_NAME],result[34];
GetPlayerName(playerid,playa,sizeof(playa));
if(strfind(playa,"_",true) != -1)
{
return result;
}
}
Could anyone help me with the rest please?
Re: Replacing "_" with an space in a string -
ReVo_ - 18.08.2012
pawn Код:
stock RemoveSymbol(playerid) {
new nickname[24];
GetPlayerName(playerid, nickname, 24);
for ( new i = 0 , j = strlen( nickname ) ; i < j ; ++ i ) {
if( nickname[ i ] == "_" ) {
nickname[i] = ' ';
}
}
return nickname;
}
returns new nickname.. try this
Re: Replacing "_" with an space in a string -
phillip875 - 18.08.2012
error 033: array must be indexed (variable "-unknown-")
Shouldnt the "if( nickname[ i ] == "_" )" use strfind?
Re: Replacing "_" with an space in a string -
aintaro - 18.08.2012
Put this anywhere in your gamemode:
Код:
stock strreplace(string[], find, replace)
{
for(new i=0; string[i]; i++)
{
if(string[i] == find)
{
string[i] = replace;
}
}
}
Place this where you want it to replace the players '_' in its name:
Код:
new pname[24];
GetPlayerName(playerid, pname, sizeof(pname));
strreplace(pname, '_', ' ');
Re: Replacing "_" with an space in a string -
phillip875 - 18.08.2012
Thankyou.
Re: Replacing "_" with an space in a string -
Sandiel - 18.08.2012
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.
Re: Replacing "_" with an space in a string -
ReVo_ - 18.08.2012
Quote:
Originally Posted by phillip875
error 033: array must be indexed (variable "-unknown-")
Shouldnt the "if( nickname[ i ] == "_" )" use strfind?
|
if ( nickname[ i ] == '_' )
correct
Re: Replacing "_" with an space in a string -
Edvin - 18.08.2012
http://forum.sa-mp.com/showthread.ph...93#post1845593 - Use this function to delete a sub-string from your string, like in player name. I don't know if it works to delete sub-strings with this function on player names, but try it
Re: Replacing "_" with an space in a string -
phillip875 - 18.08.2012
Anyone know how to replace [ and ] since it registers as invalid symbol?