SA-MP Forums Archive
split doesn't work - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: split doesn't work (/showthread.php?tid=165878)



split doesn't work - r0b - 06.08.2010

Hello sa-mp.com forum,
i need help with split. I want to split the string data into the array tmp. I did it with this function:
Код:
forward split(const strsrc[], strdest[][], delimiter);
public split(const strsrc[], strdest[][], delimiter)
{
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc))
    {
        if(strsrc[i] == delimiter || i == strlen(strsrc))
        {
            len = strmid(strdest[aNum], strsrc, li, i, 128);
            strdest[aNum][len] = 0;
            li = i+1;
            aNum++;
        }
        i++;
    }
}
Here I used the function:
Код:
new tmp[13][128];
split(data,tmp,"|");
This is what the compiler says:
Код:
error 035: argument type mismatch (argument 3)
to the line with split(..);


Re: split doesn't work - JaTochNietDan - 06.08.2010

Split accepts a single character rather than a string for splitting, like so

pawn Код:
split(data,tmp,'|');



Re: split doesn't work - r0b - 06.08.2010

This is exactly what i did:
Код:
split(data,tmp,"|");
Or not?

EDIT:
Ah, i changed the " " and it works now. But why? Explain pls..what is the difference between " and ' ?


Re: split doesn't work - JaTochNietDan - 06.08.2010

Quote:
Originally Posted by r0b
Посмотреть сообщение
This is exactly what i did:
Код:
split(data,tmp,"|");
Or not?
The " defines it as a string, ' defines it as a character.

" is a double quote.
' is an apostrophe.

They may look similar but to the computer they are both very different, so make sure you input the right one

That split function is designed to accept a single character only for the splitting process.


Re: split doesn't work - r0b - 06.08.2010

Okay, thank you very much now. I tested it, it works fine now.