strfind looping problem..
#1

Ok, first off, i'm trying to detect how many "~n~"'s are in a string, the way i do it is. i first find the first ~n~, then save that position in the string with strfind, then start at that position for the next find, but yet. currentrow always return 0
pawn Код:
new Rows = 0, Currentrow = 0, R = -1, Float:PositionY;
    for(new i = 0; i != 14; i++)
    {
        R = strfind(text, "~n~", true, Currentrow);
        if(R != -1)
        {
            Rows ++;
            Currentrow = R;
            printf("Currentrow: %d", Currentrow);
        }
    }
    printf("Rows: %d", Rows);
edit below, i forgot to put the string i was trying to find in.

"~n~Hello~n~~n~"

so ya, if i start currentrow at 0, it can't start at currentrow + 1
Reply
#2

pawn Код:
new Rows = 0, Currentrow = -1/*It is -1 for the Currentrow + 1 below*/, R = -1, Float:PositionY;
for(new i = 0; i != 14; i++)
{
    R = strfind(text, "~n~", true, Currentrow + 1);//
    if(R != -1)
    {
        Rows ++;
        Currentrow = R;
        printf("Currentrow: %d", Currentrow);
    }
}
printf("Rows: %d", Rows);
The position means where it starts to search.
So if the first time it find it at cell 0, the next strfind will start to search at 0, which will match the ~n~ at cell 0 again.
If you have Currentrow + 1, it will start at cell 1 to search again, so that it will not match the previous one.
Reply
#3

anyways.. thanks for trying, i looked at Ryder`'s previous strfind using functions, and i built it off of it. rep++ to him.

thanks for suggesting and trying .
pawn Код:
new Rows = 0, Currentrow = -1, Float:PositionY;
    while((Currentrow = strfind(text, "~n~", true, (Currentrow + 1))) != -1)
    {
        Rows ++;
        printf("Currentrow: %d", Currentrow);
    }
that is my solution for now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)