News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Load File To String & Save String As File

Started by kevin, April 03, 2011, 12:58:56 AM

Previous topic - Next topic

kevin

 Load File To String & Save String As File

  Here's a couple of functions for loading complete files into a string, and it's opposite for saving the string as file.  


PlayBASIC Code: [Select]
Function LoadFileToString(file$)
if FIleexist(file$)
size=filesize(file$)
ThisBank=NewBank(size+256)
f=readnewfile(file$)
readmemory f,GetBankPtr(ThisBank),size
closefile f
result$=peekbankstring(ThisBank,0,size)
deletebank thisbank
endif
EndFunction Result$


Function SaveStringAsFile(file$,ThisString$)
if FIleexist(file$)
deletefile file$
endif
size=Len(ThisString$)
ThisBank=NewBank(size+256)
PokeBankString ThisBank,0,ThisString$,0
f=Writenewfile(file$)
Address=GetBankPtr(ThisBank)
writememory f,Address,Address+size
closefile f
deletebank thisbank
EndFunction





Related Examples

 * Load TextFiles To String Array