String splitting to Arrays

BlitzMax Forums/BlitzMax Programming/String splitting to Arrays

klepto2(Posted 2005) [#1]
In my module I have got 2 methods for splitting Strings and send them to an Array. I have made 2 functions out of them to share them with you.

The first one called Return_strip devides the string as often it finds the delivered ASCII code in the String.

The second one called Return_strip2 devides the string as long as the delivered _strip:string is. i.e: the stripstring is
" :" the main string will be divided two times.
("Load Map:Test.dat" will result in 1. "load" and 2. "Map:Test.dat" with the first function but with the second one you will get : 1."Load" 2."Map" 3."Test.Dat")




Perturbatio(Posted 2005) [#2]
I added something similar to the code archives except it returns a list rather than an array.


klepto2(Posted 2005) [#3]
Well, I haven't looked in the Codearchives for a long time.
And in an other topic someone searched for this.

Yours is nice, I wished I had seen it before.


Perturbatio(Posted 2005) [#4]
As long as yours works it doesn't really matter.

Hmm... it might be interesting to speed test them to find out which is faster.


klepto2(Posted 2005) [#5]
Would be nice but it seems both needs 0 millisecs.

Tested with this code:



Results :

1: 0
2: 0
3: 14 (last one was a test if my test is correct)


Perturbatio(Posted 2005) [#6]
well, a better test would be to do it a thousand times:


This shows that mine is slower (which is what I suspected).
It is sometimes however handy to have the list functionality.

*EDIT*
Mine can be sped up slightly by not creating the list each loop (i.e. create it outside the loop and the assign to it inside).


Perturbatio(Posted 2005) [#7]
Actually, this is weird, mine performs better if you run it first:


*EDIT*
solved it:


Flushmem is your friend.

I get:
Pertubatios :
needed time: 25
Return_strip :
needed time: 15
Testloop :
needed time: 43
in Debug Mode

and:
Pertubatios :
needed time: 18
Return_strip :
needed time: 14
Testloop :
needed time: 11
in Release.

Yours is still faster, but it makes me feel better that mine isn't quite as horrendously slow as I thought.


Jay Kyburz(Posted 2005) [#8]
mind if i ask why you start your vars with underscore, is this a basic convention?


klepto2(Posted 2005) [#9]
@Hakea :If you mean '_' this with underscore then I actually use it because I have seen somewhere else and it looks much better for me and it helps me not to loose the overview in greater projects.

@Pertubatio : Yeah that flushmem() works wonders ;)