Here my version :
Code:
ExplodeString ( const string[], output[], olen = sizeof output )
{
new len = strlen( string ); // We retrieve the length of the current string passed.
if ( !len ) { return 0; } // If the string is empty we stop there.
new i, c, j, count;
new number[ 12 ];
do
{
while ( string[ i ] == ' ' ) i++; // One or more spaces can be used between 2 numbers, so we move forward until we find a number.
while ( ( number[ j++ ] = c = string[ i++ ] ) && c != ' ' ) {} // We loop and save the number found until the next space found or end of string.
output[ count++ ] = str_to_num( number ); // We convert the number saved previously into a number and we stored in output at the slot count.
j = 0;
}
while ( i < len && count < olen ) // We should looping while we have not cross the string length.
return count;
}
Code:
new myString[ 128 ];
get_pcvar_string( myPointer, myString, charsmax( myString ) );
new myNumbers[ 24 ];
new count = ExplodeString( myString, myNumbers );
if ( count )
{
log_amx( "Count = %d", count );
for ( new i; i < count; i++ )
{
log_amx( "%d - %d", i, myNumbers[ i ] );
}
}
Example with :
Code:
" 54 1421 141 1 4622"
output :
Code:
[Untitled.amxx] Count = 5
[Untitled.amxx] 0 - 54
[Untitled.amxx] 1 - 1421
[Untitled.amxx] 2 - 141
[Untitled.amxx] 3 - 1
[Untitled.amxx] 4 - 4622
__________________