SA-MP Forums Archive
Strip spaces from 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: Strip spaces from string (/showthread.php?tid=518422)



Strip spaces from string - mrxqware - 09.06.2014

Dear Peeps


It might sound a bit stupid but I've got problems with this code to strip spaces from a string:

Код:
stock RemoveSpace(string[])
{
    for(new i=0; string[i]; i++)
    {
        if(string[i] == " ")
        {
            string[i] = "";
        }
    }
return string;
}
It's giving the following errors:

Код:
C:\Users\Mike\Desktop\Server\gamemodes\gamemode.pwn(134096) : error 033: array must be indexed (variable "-unknown-")
C:\Users\Mike\Desktop\Server\gamemodes\gamemode.pwn(134097) : error 027: invalid character constant
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase
Could you help me to find the problem please?


greetings and thank you,
Mike

2 Errors.


Re : Strip spaces from string - Lacamora - 09.06.2014

use the trim function

http://forum.sa-mp.com/showthread.ph...t=slice+string


Re: Strip spaces from string - Djole1337 - 09.06.2014

pawn Код:
....



Re: Strip spaces from string - Vince - 09.06.2014

Use ' instead of " for single characters. However, I don't think that it's possible to replace a space with "nothing". I think you will need to shift everything and then restart the search. Something like this (untested)

pawn Код:
new pos = -1;

while((pos = strfind(string, " ")) != -1)
{
    for( ; pos < size - 1; pos++)
    {
        string[pos] = string[pos+1];
    }
}
Note: if the compiler complains about indeterminate array size, then edit the function header:
pawn Код:
stock RemoveSpace(string[], size = sizeof string)