How to count how many '\t' a string has.
#1

I know, it's all about loops, but i couldn't manage it so that it counts correctly, this is what i have
pawn Код:
new Cmd,t,s[sizeof(Str8)];
    format( s, sizeof s, "%s", Str8 );
   
   
    for ( new x = sizeof( s ); t < x; t++ )
    {
        if ( strfind( s[ t ], "\t", false ) == 0 )
        {
            Cmd++;
            FormMessage( playerid, -1, ""CLB"%d", Cmd );
        }
    }
It does work, but gives me a big number, like 357 but i don't think the string has that much :O.
I put the message into the loop jsut for fun.
Reply
#2

pawn Код:
stock countTabulatedOccurrences(string[]) {
    new
        tCount;
       
    for(new it = 0; it < strlen(string); it++) {
        if(string[it] == '\t') tCount++;
    }
   
    return tCount;
}
Tested and works.

'\t' is not a string, it is just a single character due to the slash making it a control character.
Reply
#3

You helped me really much, thanks a bunch!

Just tested, OMG i really do have 357 \t's :O, i did a good code, yay for me


Thanks for the stock anyway
!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)