UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on April 03, 2011, 12:58:56 AM

Title: Load File To String & Save String As File
Post by: kevin on April 03, 2011, 12:58:56 AM
 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.  


[pbcode]

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

[/pbcode]


Related Examples

 * Load TextFiles To String Array (http://www.underwaredesign.com/forums/index.php?topic=1917.0)