Raised This Month: $ Target: $400
 0% 

Parse string cvar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
polodu94
Senior Member
Join Date: Jun 2010
Old 07-26-2010 , 06:54   Parse string cvar
Reply With Quote #1

Hello,

I want to use this function ( parse( ) ) but i don't now how to use it.

I have my string cvar :

PHP Code:
16000 800 14000 
This cvar can be vary between 0 and 24 values ( ir we have 3 values ^^ )

I want to get back the values but i don't know how when the number of values vary.

PS : Sorry for my english

Thank you for Answers
polodu94 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-26-2010 , 07:05   Re: Parse string cvar
Reply With Quote #2

http://www.amxmodx.org/funcwiki.php?go=func&id=58 you have an exemple. Also you can seach, you will find numerous others exemples.
__________________
Arkshine is offline
polodu94
Senior Member
Join Date: Jun 2010
Old 07-26-2010 , 07:08   Re: Parse string cvar
Reply With Quote #3

Yes but ir we know the number of arg.

Me i don't know the number of arg can be vary ( 0 of 24 )

If the number can't be vary yes the exaemple is good for me but it's not the case
polodu94 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-26-2010 , 07:26   Re: Parse string cvar
Reply With Quote #4

It doesn't matter. You can still used parse(). But it won't be appropriate.
You could use strbreak(), looping until the right output is empty. Something like that.
__________________
Arkshine is offline
polodu94
Senior Member
Join Date: Jun 2010
Old 07-26-2010 , 07:41   Re: Parse string cvar
Reply With Quote #5

Arkshine thank you for help but i prefere with exemple can you make it because i don't understand you explications.

With my exemples, with the randomnumber of arg

Plz
polodu94 is offline
G[o]Q
Member
Join Date: Jan 2010
Location: Poland (Malopolska)
Old 07-26-2010 , 16:46   Re: Parse string cvar
Reply With Quote #6

try this:
Code:
parse_item(string[],len,output[][]){
new bufor[1024];
new ile=0
for(new i=0 ;i<strlen(string);i++){
        if(!equal(string[i]," ")){
                format(bufor,1023,"%s%c",bufor,string[i]);
        }
        else
        {
                copy(output[ile],63,bufor);
                bufor = "";
                ile++
        }

}
return ile
}
Use
Code:
new string[]="asda dadawd addadaw"
new out[24][64]
new number= parse_item(string,sizeof string,output)
after use

Code:
out[0]="asda"
out[1]="dadawd"
out[2]="addadaw"
function return number of parsed items you can use this in
Code:
for(new i=0;i<number;i++) client_print(0,print_chat,"%s",out[i])

Last edited by G[o]Q; 07-26-2010 at 17:56.
G[o]Q is offline
polodu94
Senior Member
Join Date: Jun 2010
Old 07-27-2010 , 06:05   Re: Parse string cvar
Reply With Quote #7

g[o]q it's that i search thank you
polodu94 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-27-2010 , 11:06   Re: Parse string cvar
Reply With Quote #8

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
polodu94
Senior Member
Join Date: Jun 2010
Old 07-27-2010 , 14:15   Re: Parse string cvar
Reply With Quote #9

nice too
polodu94 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-27-2010 , 14:24   Re: Parse string cvar
Reply With Quote #10

Mine is better coded. And also more suit for your need.
__________________
Arkshine is offline
Reply


Thread Tools
Display Modes

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