Delete underscore from string -
Garwan50 - 15.08.2013
Hello,
i try to delete an underscore (_) from a string, i try to do it in two differents way, but it does'nt work:
1st way:
pawn Код:
stock RPName(name[])
{
new NameLenght = strlen(name);
new value = strfind(name, "_", true);
strdel(name, value, value+1);
strins(name, " ", value, NameLenght);
return name;
}
It return |dњfirstname lastname, so it work but i don't understand why there are |dњ before the name, i try to delete the three first caracter but it does'nt work.
The second way:
pawn Код:
stock Underscore(name[])
{
for(new i=0; i<strlen(name); i++)
{
if (name[i] == "_") //
{
name[i] = " ";
return name;
}
}
return 1;
}
but it show some errors
Quote:
C:\Users\PC-HP\Desktop\pawno\gamemodes\test.pwn(1297) : error 033: array must be indexed (variable "-unknown-")
C:\Users\PC-HP\Desktop\pawno\gamemodes\test.pwn(1299) : error 006: must be assigned to an array
C:\Users\PC-HP\Desktop\pawno\gamemodes\test.pwn(1303) : error 079: inconsistent return types (array & non-array)
|
Re: Delete underscore from string -
Misiur - 15.08.2013
pawn Код:
stock Underscore(name[])
{
for(new i = 0, j = strlen(name); i != name; i++)
{
if (name[i] == '_') //
{
name[i] = ' ';
break;
}
}
return name;
}
If you delete the break, then all _ will be replaced, otherwise only first one. Also "_" is not equal to '_'. "_" is in fact string, array of 2 elements '_', '\0', and you need only character, so use single quotes
Re : Delete underscore from string -
Garwan50 - 15.08.2013
Hi and thanks. Unfortunately, same problem, a |doe before the name :/
Re: Delete underscore from string -
Jefff - 15.08.2013
pawn Код:
for(new i = 0, j = strlen(name); i != j; i++)
Re: Delete underscore from string -
Alexis1999 - 15.08.2013
pawn Код:
stock RemoveBracket(playerid)
{
new szName[MAX_PLAYER_NAME];
GetPlayerName(playerid, szName, sizeof(szName));
for(new i = 0; i < MAX_PLAYER_NAME; i++)
{
if(szName[i] == '_') szName[i] = ' ';
}
return szName;
}
Usage:
pawn Код:
new SzString[128];
format(SzString, sizeof(SzString), "%s", RemoveBracket(playerid));
And there you have it
Re : Re: Delete underscore from string -
Garwan50 - 15.08.2013
Quote:
Originally Posted by Jefff
pawn Код:
for(new i = 0, j = strlen(name); i != j; i++)
|
pawn Код:
for(new i = 0; i < strlen(name); i++)
Its the same no ?
@Alexis1999: I want to delete underscore from a string.
Re: Re : Re: Delete underscore from string -
Djole1337 - 15.08.2013
Quote:
Originally Posted by Garwan50
pawn Код:
for(new i = 0; i < strlen(name); i++)
Its the same no ?
@Alexis1999: I want to delete underscore from a string.
|
Jefff's loop is somewhat faster.
Re : Delete underscore from string -
Garwan50 - 15.08.2013
Ok, but it does'nt work :/
Re: Delete underscore from string -
MSuperXX - 15.08.2013
Try this one, I think will help you
pawn Код:
GiveNameSpace(str[])
{
new strl;
strl=strlen(str);
while(strl--) {
if(str[strl]=='_') str[strl]=' ';
}
return 0;
}
For example:
pawn Код:
new myname[MAX_PLAYER_NAME];
GetPlayerName(playerid, myname, sizeof(myname));
GiveNameSpace(myname);
new string[128];
format(string, sizeof(string), "%s", myname(playerid));
Re : Delete underscore from string -
Garwan50 - 15.08.2013
Yes but i want to know what's wrong with my code ^^, thanks anyway