Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AbrahamR, wdlmaster, 7th_zorro, dr_panther, 1 invisible), 764 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Split question. #217371
07/22/08 20:48
07/22/08 20:48
Joined: May 2007
Posts: 185
Netherlands
SurudoiRyu Offline OP
Member
SurudoiRyu  Offline OP
Member

Joined: May 2007
Posts: 185
Netherlands
Hi,
i was wondering if there is a command to split an array?
Like there is in Python Scripting.

Like the array is filled with:

Code:
MyArray = ["hello,there,all"]

If i acces my array now it will look like
MyArray[0] = hello,there,all
Now i want to split the array everywhere where the "," is.
So the array becomes:
MyArray[0] = hello
MyArray[1] = there
MyArray[2] = all

Can someone help me out ?


Greetzzz,


-The Dragon's Eye is alway's watching you!-
Re: Split question. [Re: SurudoiRyu] #217619
07/24/08 02:13
07/24/08 02:13
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Lite-c is no script language like PHP or Python, it's a programming language. You have to code such a function yourself. But first look if you really need this, because you shouldn't if you program your stuff well.


Click and join the 3dgs irc community!
Room: #3dgs
Re: Split question. [Re: Joozey] #217634
07/24/08 07:24
07/24/08 07:24
Joined: May 2007
Posts: 185
Netherlands
SurudoiRyu Offline OP
Member
SurudoiRyu  Offline OP
Member

Joined: May 2007
Posts: 185
Netherlands
Hmm,
ok Python is aswell programming language wink im working with it on my work.

btw,
Let me explain:

I have a Database connected and got a cell in it i need
It is filled with: "Hallo, daaro, allemaal"
Now i set it in a string but it will be just like the Database.
I want to split the cell whereever is a comma ","
So i get an array with 3 items
MyArray[0] = "Hallo"
MyArray[1] = "daaro"
MyArray[2] = "allemaal"

Can u help me a little bit with it ?

Thnx allready,


-The Dragon's Eye is alway's watching you!-
Re: Split question. [Re: SurudoiRyu] #217679
07/24/08 11:28
07/24/08 11:28
Joined: Aug 2005
Posts: 1,230
M
MichaelGale Offline
Serious User
MichaelGale  Offline
Serious User
M

Joined: Aug 2005
Posts: 1,230
Fairly simple actually. Firstly you iterate through all chars in the source string and count the occurrences of the separator char. Then you allocate a new string array (num_separator_chars + 1). Finally you iterate a second time through all characters of the string and append them to the new string array.

Another way would be to use a dynamic array/list, but I am not quite sure which method is the faster one.


Your friendly mod is at your service.
Re: Split question. [Re: MichaelGale] #217682
07/24/08 11:38
07/24/08 11:38
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Quote:
Hmm,
ok Python is aswell programming language wink im working with it on my work.

Oh yes, I switched python with perl, my bad. So my answer was practically nonsense. But nevertheless you have to program it yourself laugh.

Michael's idea about a dynamic array/list is possible, and I think it's alot faster since you only make use of pointers after the mysql library allocated the resultset.

I am developping an sql plugin that returns a dynamic multidimensional array with various data from columns (integers, strings, everything), and also any error message, but it's not yet publicly available. It works quite well though. If you have time/are interested in trying, contact me smile.


Last edited by Joozey; 07/24/08 11:39.

Click and join the 3dgs irc community!
Room: #3dgs
Re: Split question. [Re: Joozey] #217799
07/24/08 21:26
07/24/08 21:26
Joined: May 2007
Posts: 185
Netherlands
SurudoiRyu Offline OP
Member
SurudoiRyu  Offline OP
Member

Joined: May 2007
Posts: 185
Netherlands
Possible to do it like
new_string = "Hallo,allemaal,daaro";
my_text.string[3] = new_string;
?

Joozey add me at msn if u want (pm me for my msn)


-The Dragon's Eye is alway's watching you!-
Re: Split question. [Re: SurudoiRyu] #218037
07/25/08 23:52
07/25/08 23:52
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
are you looking to re-create the string.split() from the .NET framework?

If so then these guys have made some small algorithms. Don't know if it's much use to you but its worth a read...

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=838990&SiteID=1

It's C# but you should be able to convert or fashion something similar in lite-c.

Last edited by DJBMASTER; 07/25/08 23:52.
Re: Split question. [Re: SurudoiRyu] #218196
07/27/08 03:23
07/27/08 03:23
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Heres the code you're after, but please forgive its "quick and dirty"ness
as I threw it together in half an hour.

Its limitations are as follows.
1) Any data already in the 'Return' array is overwritten and/or lost and may be classified as a memory leak.
2) Hard-coded to be COMMA delimiters ONLY. (but you could change that yourself if you want to, it only appears on one line)
3) The 'Return' array does NOT get resized so if its was declared too big and you dont stop at the returned
index-count, or if it was initially declared too small, run-time errors MAY result (data dependant !!BAD!!).
4) If the source string ENDS with a comma, the last empty item will be ignored, so add a space after the comma
and it will be retained as a single space character string.

So this function will be useful if youve got a rough idea how many entries there will be. But unsafe to use of you
are reading unknown lengths of data(say from a externally generated file).

I'll post it as a starting point for others to work from.
So no usage rights are required.

Heres the routine itself



Code:
//
function StringSplit(STRING* *ReturnArray, STRING* SourceString)
{
   if(str_len(SourceString)==0)      {   printf("StringSplit-->Invalid SourceData");   return;   }
   var ItemCount=0;   var tmp;
   STRING* TempData = str_create(SourceString);	
   //
   while(str_len(TempData)>0)   // Build Data Array
   {	
      ReturnArray[ItemCount] = str_create(TempData);   //Initialise THIS item
      tmp = str_stri(TempData, ",");               //Find Delimiter
      if(tmp!=0)
      {  str_trunc(ReturnArray[ItemCount], str_len(TempData) - tmp + 1);   // Remove Delimiter and beyond from Item
         str_clip(TempData, tmp);      }      // Remove "Used" TempData
      else   {   str_cpy(TempData,"");   }
      if(str_len(TempData)>0)   {   ItemCount += 1;   }
   }
   return(ItemCount+1);
}
//

And heres some code to show how its used and to see it in action, just open the ACKLOG.TXT when you've run the code.

Code:
   ...
   STRING* ResultArray[50];
   var Count = StringSplit(ResultArray,"Entry1,Entry2,Entry3,Entry4,Entry5,Entry6,Entry7,Entry8,Entry9,Entry10");
   //
   STRING* tmpStr = "#100";
   diag("\n\nStringSplit Returned ");
   diag(str_for_num(tmpStr,Count));
   diag(" Entries.\n");
   var cnt;
   for (cnt=0; cnt<Count; cnt++) 	
   {
      diag(str_for_num(tmpStr,cnt));      diag("=\"");
      diag(ResultArray[cnt]);             diag("\"\n");
   }
   ...

Enjoy!


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Split question. [Re: EvilSOB] #218197
07/27/08 03:37
07/27/08 03:37
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
As you can see from my above coding, there are several dangers in passing pre-declared arrays.

As you can also see, the core of the code is quite small, so I would STRONGLY suggest you actually include the code
WITHIN the function that declares the result array and bypass all the serious risks with array passing.
I'll try to get an example posted later today or tomorrow.

Either way, you should also call a str_remove() on each array entry after it is used, or on every entry in the array
before exiting or each un-removed entry will become "leaked" memory.

Best of luck, and feel free to ask questions.

PS EXPERTS - sideline question here, please clarify my understanding here.
If you declare structures and/or array pointers as local variables, and fill them using
creation functions (eg str_create), does the contents of those pointers get purged on the function
closing/terminating or does the contents become "leaked memory" (as I understand is the case).
Does it vary between pointer types or anything if I am wrong?
Thanks


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Split question. [Re: EvilSOB] #218344
07/28/08 07:30
07/28/08 07:30
Joined: May 2007
Posts: 185
Netherlands
SurudoiRyu Offline OP
Member
SurudoiRyu  Offline OP
Member

Joined: May 2007
Posts: 185
Netherlands
Wow thnx EvilSOB,
I will look into your script and gonna do some test's with it.
Maybe i can change some things in it.

Thnx for the example and de help,
Hope i can go bit further now.

Greetzzz,


-The Dragon's Eye is alway's watching you!-
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1