Slice Arrays

BlitzMax Forums/BlitzMax Programming/Slice Arrays

Smokey(Posted 2004) [#1]
Hi

I just bought Max and I think that is a good move considering the flexibility compared to blitzB.

For Arrays, I can redim by slicing but can It preserve
the actual data that the arrays contain?


bradford6(Posted 2004) [#2]
yes
' arrays
Graphics 800,600,0

Local myarray:String[]=["fe","fi","fo","fum"]

Original$ = " Myarray consists of  "+Len(myarray)+" elements: "

For foo$ = EachIn myarray
	cnt = cnt + 1
	If cnt>1 Then original$ = original$ + " , "
	original$ = original$ + foo$
	
next
cnt = 0
myarray = myarray[..2]
sliced$ = " New (sliced) Myarray consists of "+Len(myarray)+" elements: "
For foo$ = EachIn myarray
	cnt = cnt + 1
	If cnt>1 Then sliced$ = sliced$ + " , "
	sliced$ = sliced$ + foo$
	
Next

DrawText (original,10,10) 
Print original
DrawText (sliced,10,30)
Print sliced
flip

waitmouse


result:
Myarray consists of 4 elements: fe , fi , fo , fum
New (sliced) Myarray consists of 2 elements: fe , fi