LoginLogin

Saving and Loading String Arrays

Root / Submissions / [.]

12Me21Created:
You can't easily save string arrays into a DAT file, but here's a way to convert a string array into a string and back, so it can be saved as a regular TXT file.

Array -> String

DEF SAVE$(ARRAY$[])
 DIM STRING$
 VAR I%
 FOR I%=0 TO LEN(ARRAY$)-1
  INC STRING$,CHR$(LEN(ARRAY$[I%]))
  INC STRING$,ARRAY$[I%]
 NEXT
 RETURN STRING$
END

String -> Array

DEF LOAD$(STRING$)
 DIM ARRAY$[0]
 VAR I%
 FOR I%=0 TO LEN(STRING$)-1
  VAR LEN%=ASC(STRING$[I%])
  PUSH ARRAY$,MID$(STRING$,I%+1,LEN%)
  INC I%,LEN%
 NEXT
 RETURN ARRAY$
END

Example Use

'saving a string array
DIM ARRAY$[3]
...
SAVE "TXT:EXAMPLE",SAVE$(ARRAY$)

'loading a string array
DIM ARRAY$[0]
ARRAY$=LOAD$(LOAD("TXT:EXAMPLE",0))

No posts yet (will you be the first?)