How to count how many '\t' a string has. - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to count how many '\t' a string has. (
/showthread.php?tid=217555)
How to count how many '\t' a string has. -
Zh3r0 - 28.01.2011
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.
Re: How to count how many '\t' a string has. -
__ - 28.01.2011
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.
Re: How to count how many '\t' a string has. -
Zh3r0 - 28.01.2011
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
!