Cuttings words out from strings
#2

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;
}
Reply


Messages In This Thread
Cuttings words out from strings - by cosbraa - 31.08.2012, 07:25
Re: Cuttings words out from strings - by Misiur - 31.08.2012, 07:43
Re: Cuttings words out from strings - by cosbraa - 31.08.2012, 09:27

Forum Jump:


Users browsing this thread: 1 Guest(s)