[Gambas-user] load file content in an array

Rob sourceforge-raindog2 at ...94...
Fri Jul 8 07:30:43 CEST 2005


On Thursday 07 July 2005 16:59, Amon Forstmann wrote:
> is it possible to load the content of a file in an array?
> For each line of that file a new array entry?

Sure.

dim f as file
dim s as string
dim sa as new string[]

' If memory use isn't a problem....

sa = split(File.Load("filename.txt"), "\n")

' If it's a big file or you're short of memory....
' I'll use 1.9.11 syntax, even though I can't test it yet ;)

f = open("filename.txt") for read
do while not eof(f)
	line input #f, s
        sa.add(s)
loop

You should consider all of the above to be pseudo-code, but it should 
help you understand the various ways of doing what you want.

Rob






More information about the User mailing list