AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Parsing help (https://forums.alliedmods.net/showthread.php?t=240887)

c2d22 05-24-2014 00:44

Parsing help
 
Question :-
PHP Code:

power class ability weapon 

Note - The amount of argument in the line will differ , it can go long !

So what i want is to parse the above line , and grab all the data in a dynamic array . Problem is amount of argument in the line is unidentified .
It can be
PHP Code:

power class ability weapon nothing asdjas sdhs zxnxzn 

How can i parse this type data which can be parsed unidentified times and push them into dynamic array?

Bugsy 05-24-2014 08:55

Re: Parsing help
 
You need to lay out some type of rules for this data ie. some consistent ordering, or prefix each data item with an identifier POWER-powervalue CLASS-theclass. A computer can only do what you tell it to do, there's no magic way for it to know what you're trying to accomplish.

Looking at your second example, are the types of arguments dynamic, or only the data items belonging to each type dynamic?

If you wanted to do like "100 1 55 AWP GLOCK HEGRENADE" (100=power, 1=class, 55=ability, then a list of weapons) then this is simple.

Give some real-life example datas so we can better understand what needs to be parsed.

Backstabnoob 05-24-2014 09:35

Re: Parsing help
 
What Bugsy said.

You didn't tell us what you want to do, but if you just want to push mixed data into a dynamic array, why not just use ArrayPushArray / ArrayGetArray?

PHP Code:

enum _ArrayData
{
   
_Data_Power,
   
_Data_Class16 ],
   
_Data_Ability256 ],
   
_Data_Weapon
}

new Array: 
g_aArray
// ...
g_aArray ArrayCreateArrayData )

// ...

new aDataArrayData ]
aData_Data_Power ] = 1
aData
_Data_Class ] = "awesome class"
// ...
ArrayPushArrayg_aArrayaData 


c2d22 05-24-2014 15:19

Re: Parsing help
 
Any ways i figured it out myself.
Note - i used "!" to differentiate the arguments
PHP Code:

new left[10] , right[20] ,count,,Array:in

for(a=<= charsmax(input) ; a++)
    if(
input[a] == '!' )
    
count++

for(
;  <= counta++)
{
    
strtok2(input,left,charsmax(left),input,charsmax(input), '!',TRIM_FULL)
    if(!
in)
    
in ArrayCreate()

    
ArrayPushString(in,left)



Backstabnoob 05-24-2014 15:58

Re: Parsing help
 
Glad to see you took the time to read my post.


All times are GMT -4. The time now is 09:35.

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