Clear Array?

BlitzMax Forums/BlitzMax Beginners Area/Clear Array?

jondecker76(Posted 2010) [#1]
I'm trying to figure out how to clear an array. I'm currently using an array in a type. See below example:

Type TtextFile
	defaults:TMap
	lines:String[]
	filePath:String

	...
	...

	Method Clear()
		filePath="" 		'Clear the file path
		defaults.clear()	'Clear the defaults map
		lines=New String[]	'Hmmm... How to clear the lines[] array?
	End Method
End Type



_Skully(Posted 2010) [#2]
For ct:int=0 to lines.length-1
   lines[ct]=""
next



plash(Posted 2010) [#3]
If you want the array to stay the same size, do
lines = New String[lines.Length]


If you want a new, empty array do
lines = New String[0]



jondecker76(Posted 2010) [#4]
aah ok, that makes sense

thanks guys


_Skully(Posted 2010) [#5]
I wonder whats faster.. the Malloc for the new array or just clearing the contents of an existing one... hmmm


Czar Flavius(Posted 2010) [#6]
A lot of people want to clear their arrays recently, is it spring-cleaning time :D