Raised This Month: $ Target: $400
 0% 

Parse string cvar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-27-2010 , 11:06   Re: Parse string cvar
Reply With Quote #1

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
__________________

Last edited by Arkshine; 07-27-2010 at 19:07.
Arkshine is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode