Spliting 3 values from a string
#1

How can I take out 3 values from a string which have a "," between them, yes ofc with split. Suppose this is the string
pawn Код:
format(string, sizeof(string),"Pos=%.1f,%.1f,%.1f\n",PlayerInfo[playerid][pPosx],PlayerInfo[playerid][pPosy],PlayerInfo[playerid][pPosz]);
Reply
#2

pawn Код:
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++;
    }
    return 1;
}
You want this?
Reply
#3

I know the split function, but I want to take out the three values in that string (the %.1f,%.1f,%.1f.....the comma's are separating the three float values.)
Reply
#4

can u do string[0] string[1] string[2]
Reply
#5

Can you show me the string please?
Reply
#6

pawn Код:
new newstr[3][75];
split(string[5], newstr, ",")
//I'd recommend using sscanf but your choice.
//If you want to use sscanf, use the following lines
//Plugin (If you have it): sscanf(string[5], "p<,>fff", X, Y, Z);
//Normal : sscanf(string[5], "p,fff", X, Y, Z);
new Float:X, Float:Y, Float:Z;
X = Floatstr(newstr[0]);
Y = Floatstr(newstr[1]);
Z = Floatstr(newstr[2]);
Reply
#7

i agree with the sscanf way, easier and faster
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)