swap string
#1

hi, i need to swap all '_' to spaces, how i can do this?

i tried some like this,but I received an error error 006: must be assigned to an array
PHP код:
for(new strlen(Player_RName[playerid])-1!= -1i--) 
    { 
        switch(
Player_RName[playerid][i]) 
        { 
            case 
'_'Player_RName[playerid][i] = " ";
        } 
    } 
Reply
#2

pawn Код:
new i = strfind(Player_RName[playerid] , "_");

if(i != -1)
{
    Player_RName[playerid][i] = ' ';
}
Reply
#3

@xVIP3Rx: That would only replace 1...

You should do it like this:

PHP код:
for(new i=strfind(Player_RName[playerid] , "_"); i!=-1i=strfind(Player_RName[playerid],"_",false,i+1))
{
    
Player_RName[playerid][i] = ' ';

Reply
#4

Thank you all!
Reply
#5

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
@xVIP3Rx: That would only replace 1...

You should do it like this:

PHP код:
for(new i=strfind(Player_RName[playerid] , "_"); i!=-1i=strfind(Player_RName[playerid],"_",false,i+1))
{
    
Player_RName[playerid][i] = ' ';

You're right, though I don't think that loop is correct, kinda confusing me

does yours code do the same as
pawn Код:
new i;
while( i != -1 )
{
    i = strfind(Player_RName[playerid] , "_");

    if(pos != -1) Player_RName[playerid][pos] = ' ';
}
?
Reply
#6

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
You're right, though I don't think that loop is correct, kinda confusing me

does yours code do the same as
pawn Код:
new i;
while( i != -1 )
{
    i = strfind(Player_RName[playerid] , "_");

    if(pos != -1) Player_RName[playerid][pos] = ' ';
}
?
My code is correct and yes it do the same as your code...but is a way faster
Reply
#7

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
My code is correct and yes it do the same as your code...but is a way faster
Right, your code is "1.71875" times faster.

@CodeBreaker: You should use his code
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)