Cuttings words out from strings - 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)
+--- Thread: Cuttings words out from strings (
/showthread.php?tid=373629)
Cuttings words out from strings -
cosbraa - 31.08.2012
Haven't had a whole lo of experience with strings, so I need a litle help.
I have a dialog which has 'Name_Here | Name_Here | $Price_Here'.
So when the dialog comes up, I want to select that listitem, and it will cut out the first Name_Here.
What can I do to cut off the first bit?
Cheers.
Re: Cuttings words out from strings -
Misiur - 31.08.2012
sscanf (with "p<|>s[16]s[16]s[16]").
Without sscanf:
pawn Код:
stock getDatItem(itemPos) {
new str[64] = "Name_here | Pancakes | $12351", len = strlen(str), pipecount = 0, start = -1, stop = -1;
new res[16];
for(new i = 0; i < len; ++i) {
if('|' == str[i]) {
if(pipecount == itemPos) start = i;
pipecount++;
if(start != -1) {
stop = i;
break;
}
}
}
if(start != -1) {
if(stop == -1) stop = len - 1 - start;
strmid(res, str, start, stop);
}
return res;
}
Untested, but you should get the idea.
`e: First bit only:
pawn Код:
stock getDatItem() {
new str[64] = "Name_here | Pancakes | $12351", i = 0, res[25];
while('\0' != str[i]) {
if('|' == str[i]) {
strmid(res, str, 0, i - 1);
break;
}
++i;
}
return res;
}
Re: Cuttings words out from strings -
cosbraa - 31.08.2012
Thanks man, it worked.