Spliting 3 values from a string - 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: Spliting 3 values from a string (
/showthread.php?tid=172852)
Spliting 3 values from a string -
||123|| - 31.08.2010
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]);
Re: Spliting 3 values from a string -
Paladin - 31.08.2010
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?
Re: Spliting 3 values from a string -
||123|| - 31.08.2010
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.)
Re: Spliting 3 values from a string -
DarrenReeder - 31.08.2010
can u do string[0] string[1] string[2]
Re: Spliting 3 values from a string -
Paladin - 31.08.2010
Can you show me the string please?
Re: Spliting 3 values from a string -
[HiC]TheKiller - 31.08.2010
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]);
Re: Spliting 3 values from a string - [L3th4l] - 31.08.2010
i agree with the sscanf way, easier and faster