Removing '_' from name
#1

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"istring[i]);
        if(
string[i] == '_'string[i] = ' ';
    }
    return 
1;
}
CMD:me(playeridparams[])
{
    new 
pName[MAX_PLAYER_NAME], action[256], string[256];
    if(
sscanf(params"s[256]"action)) return SendClientMessage(playeridCOLOR_GREY"[Usage] /me [Action]");
    
GetPlayerName(playeridpNamesizeof(pName));
    
format(stringsizeof(string), "* %s %s", NameSpace(pName), action);
    
ProxDetector(2playeridstring0xC982E8FF0xC982E8FF0xC982E8FF0xC982E8FF0xC982E8FF);
    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
Reply
#2

return the edited string instead of 1
Reply
#3

Код:
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..."
Reply
#4

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.
Reply
#5

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".
Reply
#6

The function replaces all underscores for spaces, and the function I posted does work.
Код:
new name[] = "Test_Test";
printf("%s", NameSpace(name));
Reply
#7

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!
Reply
#8

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;
}
Reply
#9

Just do this
PHP код:
UnderScoreRemoveName[ ] )
{
    new 
i;
    while( ( 
strfindName"_" ) ) != -)
        
Name] =  ' ';

Or if you just want it for temporary purposes create a copy using memcpy or strcat and return it.
PHP код:
UnderScoreRemoveName[ ] )
{
    new 
tempMAX_PLAYER_NAME ];
    
strcattemp Name MAX_PLAYER_NAME );
    while( ( 
strfindtemp "_" ) ) != -)
        
temp[i]= ' ';
    return 
temp;

Reply
#10

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)