Strip spaces from string
#1

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

use the trim function

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

pawn Код:
....
Reply
#4

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)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)