swap string - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: swap string (
/showthread.php?tid=584019)
swap string -
CodeBreaker - 01.08.2015
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 i = strlen(Player_RName[playerid])-1; i != -1; i--)
{
switch(Player_RName[playerid][i])
{
case '_': Player_RName[playerid][i] = " ";
}
}
Re: swap string -
xVIP3Rx - 01.08.2015
pawn Код:
new i = strfind(Player_RName[playerid] , "_");
if(i != -1)
{
Player_RName[playerid][i] = ' ';
}
AW: swap string -
Kaliber - 01.08.2015
@xVIP3Rx: That would only replace 1...
You should do it like this:
PHP код:
for(new i=strfind(Player_RName[playerid] , "_"); i!=-1; i=strfind(Player_RName[playerid],"_",false,i+1))
{
Player_RName[playerid][i] = ' ';
}
Re: swap string -
CodeBreaker - 01.08.2015
Thank you all!
Re: AW: swap string -
xVIP3Rx - 01.08.2015
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!=-1; i=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] = ' ';
}
?
AW: Re: AW: swap string -
Kaliber - 01.08.2015
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
Re: AW: Re: AW: swap string -
xVIP3Rx - 01.08.2015
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