Cuttings words out from strings
#1

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

Thanks man, it worked.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)