Raised This Month: $ Target: $400
 0% 

Moving a String into a array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EKS
Veteran Member
Join Date: Mar 2004
Location: Norway
Old 10-11-2004 , 00:34   Moving a String into a array
Reply With Quote #1

Code:
new MyString[84] = "de_dust de_aztec de_nuke de_inferno"

Now, i need a way to split this string up into this array
Code:
new MyArray[20][20]
But the problem, is that MyString will not allways contain the same ammunt of words, So i need a way thats more "dynamic".

I tried doing:
Code:
    for(new i=1;i<=g_NumberOfMaps;i++)          parse(MyString,MyArray[i],23)
But then it only copies the first Text ( in this case de_dust) over and over. So if someone can think of a nice and clean way of this it would save me a head ake.
EKS is offline
twistedeuphoria
Veteran Member
Join Date: Jul 2004
Old 10-11-2004 , 00:51  
Reply With Quote #2

How about doing something like:
Code:
new len,mystring[84],i len = format(mystring,83,"w/e") for(i=0;blah;i++)    len += format(mystring[len],83-len,"new w/e")

then parse it like:
Code:
 parse(mystring,myarray[0],19 ... etc etc)
__________________
twistedeuphoria is offline
BAILOPAN
Join Date: Jan 2004
Old 10-11-2004 , 01:33  
Reply With Quote #3

parse is bad. create a maximum limit to the size and work from there to manually break the string.
__________________
egg
BAILOPAN is offline
Zor
Veteran Member
Join Date: Mar 2004
Location: Toronto, ON
Old 10-11-2004 , 10:04  
Reply With Quote #4

Hmmm...You could use Parse and Array. Are you getting this text from a text file? So instead of Parse use the new one:

Code:
strtok(const text[], Left[], leftLen, Right[], rightLen, token=' ', trimSpaces=0)
I'll assume that strtok will return the length of the string taken....

So I would look at it like this:

Code:
//Global
new MyString[84] = "de_dust de_aztec de_nuke de_inferno"
new MyArray = new_list_string()

public plugin_cfg()
{
     new mapName[32]

     while((strtok(MyString, mapName, 31, MyString, 83, ' ', 1)) > 0)
     {
          list_push_string(MyArray, mapName)
     }
}
....
Code
....

public plugin_end()
{
    list_delete_string(MyArray)
}
....
Code
....

public MapChange(param[])
{
     new positonIwant = str_to_num(param[0])
     new mapName[32]
     list_get_string ( MyArray, positonIwant, mapName, 31)
     server_cmd("changelevel %s", mapName)
}
Well thats about it. Now thats about as dynamic as you can get it. And there are probably some errors in it. But its an idea.

Cheers!
__________________
Zor is offline
Send a message via AIM to Zor Send a message via MSN to Zor Send a message via Yahoo to Zor
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 10-11-2004 , 12:03  
Reply With Quote #5

You could try BAILOPAN's array module to make it more dynamic.
__________________
hello, i am pm
PM is offline
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 10-11-2004 , 12:16  
Reply With Quote #6

Code:
new len=0, i=0 while (len >= strlen(mymaps)) { len = copyc(mymaps[len],maps[i],32) i++ }
Should work, I can't really remember the correct syntax for it atm
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
Zor
Veteran Member
Join Date: Mar 2004
Location: Toronto, ON
Old 10-11-2004 , 12:31  
Reply With Quote #7

Ummmm....thats what I put PM!!! Heheheheh

Cheers!
__________________
Zor is offline
Send a message via AIM to Zor Send a message via MSN to Zor Send a message via Yahoo to Zor
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 10-11-2004 , 15:49  
Reply With Quote #8

I think I solved something similar along time ago by using parse, getting one word at a time. Right after parse I cut that parsed chunk off, and reparsed until I got it all.
Nothing dynamic about the array to store to though. Small is the opposite of dynamic :-\
Johnny got his gun is offline
Zor
Veteran Member
Join Date: Mar 2004
Location: Toronto, ON
Old 10-11-2004 , 16:30  
Reply With Quote #9

True, but with the Array Module you get the Dynamics! Which is great!
__________________
Zor is offline
Send a message via AIM to Zor Send a message via MSN to Zor Send a message via Yahoo to Zor
EKS
Veteran Member
Join Date: Mar 2004
Location: Norway
Old 10-11-2004 , 17:59  
Reply With Quote #10

Quote:
Originally Posted by Johnny got his gun
I think I solved something similar along time ago by using parse, getting one word at a time. Right after parse I cut that parsed chunk off, and reparsed until I got it all.
Nothing dynamic about the array to store to though. Small is the opposite of dynamic :-\
perhaps dynamic is not the right word.
But the amont of words(maps) is gonna change . so it needs to work with "any" amount of maps.
What plugin did you do this in?
EKS 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 17:27.


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