Removing '_' from name -
javad - 16.06.2017
Hello everyone,
I'm trying to remove underline from the players name but can't.
PHP код:
forward NameSpace(string[]);
public NameSpace(string[])
{
new len;
len = strlen(string);
for(new i=0;i<len;i++)
{
printf("letter %i is %s", i, string[i]);
if(string[i] == '_') string[i] = ' ';
}
return 1;
}
CMD:me(playerid, params[])
{
new pName[MAX_PLAYER_NAME], action[256], string[256];
if(sscanf(params, "s[256]", action)) return SendClientMessage(playerid, COLOR_GREY, "[Usage] /me [Action]");
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "* %s %s", NameSpace(pName), action);
ProxDetector(2, playerid, string, 0xC982E8FF, 0xC982E8FF, 0xC982E8FF, 0xC982E8FF, 0xC982E8FF);
return 1;
}
And I get this in console:
Код:
[00:29:00] letter 0 is FirstName_LastName
[00:29:00] letter 1 is irstName_LastName
[00:29:00] letter 2 is rstName_LastName
[00:29:00] letter 3 is stName_LastName
[00:29:01] letter 4 is tName_LastName
[00:29:01] letter 5 is Name_LastName
[00:29:01] letter 6 is ame_LastName
[00:29:01] letter 7 is me_LastName
[00:29:01] letter 8 is e_LastName
[00:29:01] letter 9 is _LastName
[00:29:01] letter 10 is LastName
[00:29:01] letter 11 is astName
[00:29:01] letter 12 is stName
[00:29:01] letter 13 is tName
[00:29:01] letter 14 is Name
[00:29:01] letter 15 is ame
[00:29:01] letter 16 is me
[00:29:01] letter 17 is e
Re: Removing '_' from name -
Toroi - 16.06.2017
return the edited string instead of 1
Re: Removing '_' from name -
javad - 16.06.2017
Код:
stock NameSpace(string[])
{
new len;
len = strlen(string);
for(new i=0;i<len;i++)
{
printf("letter %i is %s", i, string[i]);
if(string[i] == '_') string[i] = ' ';
}
return string;
}
Changed it to stock.
Same problem but now I only get the star(*) ingame and nothing else when I type "/me blabla..."
Re: Removing '_' from name -
CheezIt - 16.06.2017
pawn Код:
NameSpace(name[])
{
for(new i = 0, j = strlen(name); i < j; i ++)
{
name[i] == '_' && (name[i] = ' ');
}
return name;
}
If you don't want it to do the replacement to the variable as we're passing the player's name by reference then consider copying the player's name to a local variable and process that variable instead.
Re: Removing '_' from name -
javad - 16.06.2017
Not working...
Код:
[00:29:00] letter 0 is FirstName_LastName
[00:29:00] letter 1 is irstName_LastName
[00:29:00] letter 2 is rstName_LastName
[00:29:00] letter 3 is stName_LastName
[00:29:01] letter 4 is tName_LastName
[00:29:01] letter 5 is Name_LastName
[00:29:01] letter 6 is ame_LastName
[00:29:01] letter 7 is me_LastName
[00:29:01] letter 8 is e_LastName
[00:29:01] letter 9 is _LastName
[00:29:01] letter 10 is LastName
[00:29:01] letter 11 is astName
[00:29:01] letter 12 is stName
[00:29:01] letter 13 is tName
[00:29:01] letter 14 is Name
[00:29:01] letter 15 is ame
[00:29:01] letter 16 is me
[00:29:01] letter 17 is e
Should it be like this?
name[i] or string[i] should go for every letter but it's not going. -_-
for example when i=7 the letter should be "a" (i guess

) but it's "me_LastName".
Re: Removing '_' from name -
CheezIt - 16.06.2017
The function replaces all underscores for spaces, and the function I posted does work.
Код:
new name[] = "Test_Test";
printf("%s", NameSpace(name));
Re: Removing '_' from name -
javad - 16.06.2017
Your function works.
I added "printf("%s", NameSpace("test_test"));" to my command.
now when I type the "/me test", I get "4ф" in console and " * hш test " in game.
wtf
I'm so confused!
Re: Removing '_' from name -
CheezIt - 17.06.2017
You gotta use a variable. If you want direct input to work then your function would be:
pawn Код:
NameSpace(const name[])
{
new player_name[MAX_PLAYER_NAME + 1];
strcat(player_name, name, sizeof(player_name));
for(new i = 0, j = strlen(player_name); i < j; i ++)
{
player_name[i] == '_' && (player_name[i] = ' ');
}
return player_name;
}
Re: Removing '_' from name -
SyS - 17.06.2017
Just do this
PHP код:
UnderScoreRemove( Name[ ] )
{
new i;
while( ( i = strfind( Name, "_" ) ) != -1 )
Name[ i ] = ' ';
}
Or if you just want it for temporary purposes create a copy using memcpy or strcat and return it.
PHP код:
UnderScoreRemove( Name[ ] )
{
new i , temp[ MAX_PLAYER_NAME ];
strcat( temp , Name , MAX_PLAYER_NAME );
while( ( i = strfind( temp , "_" ) ) != -1 )
temp[i]= ' ';
return temp;
}
Re: Removing '_' from name -
jlalt - 17.06.2017
Your function is doing well, but actually you're editing the string directly so you had to do
Код:
forward NameSpace(string[]);
public NameSpace(string[])
{
new len;
len = strlen(string);
for(new i=0;i<len;i++)
{
printf("letter %i is %c", i, string[i]); // %s for string %c for char
if(string[i] == '_') string[i] = ' ';
}
return 1;
}
CMD:me(playerid, params[])
{
new pName[MAX_PLAYER_NAME], action[256], string[256];
if(sscanf(params, "s[256]", action)) return SendClientMessage(playerid, COLOR_GREY, "[Usage] /me [Action]");
GetPlayerName(playerid, pName, sizeof(pName));
NameSpace(pName);
format(string, sizeof(string), "* %s %s", pName, action);
ProxDetector(2, playerid, string, 0xC982E8FF, 0xC982E8FF, 0xC982E8FF, 0xC982E8FF, 0xC982E8FF);
return 1;
}