split doesn't work
#1

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

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

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

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 ' ?
Reply
#4

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)