? Saving and Loading String Arrays ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
Creep into the Halloween / Horror Programming Contest (Deadline Extended)

Saving and Loading String Arrays

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))
Author
12Me21
Updated
Rating
2 votes
Categories
Keywords
0 Comment(s)