strip function
#1

I'm trying to make a strip function that will strip leading and trailing spaces and extra spaces from within a string, it should function like this:

input:
Код:
 The quick  brown  fox   jumps    over     the      lazy      dog.
ouput:
Код:
The quick brown fox jumps over the lazy dog.
but the function I made is not taking out the 1 leading space before the first non space character.

function:
pawn Код:
stock strip(const s[])
{
    new
        j = 0,
        tmp[256];
    if(isnull(s))
      return tmp;
    for (new i = 0; (s[i] != '\0' && s[i] != '\t'); i++)
    {
        if ((s[i] == ' ') && (s[i+1] == ' ' || s[i+1] == '\0'))
        {
        }
        else
        {
            tmp[j] = s[i];
            j++;
        }
    }
    return tmp;
}
Anyone know whats wrong?
Reply


Messages In This Thread
strip function - by StrickenKid - 23.11.2009, 23:57
Re: strip function - by -xy! - 24.11.2009, 00:37
Re: strip function - by StrickenKid - 24.11.2009, 01:53
Re: strip function - by Dabombber - 24.11.2009, 01:55
Re: strip function - by StrickenKid - 24.11.2009, 02:34

Forum Jump:


Users browsing this thread: 1 Guest(s)