Write/Read Memblock Strings

Started by kevin, July 26, 2003, 10:53:50 AM

Previous topic - Next topic

kevin

These functions are for dumping/Reading a strings into/from a memblock.  

Note: The String is stored with a word as it's length, rather than being null terminated.  This means your strings can only be a max of 65535 characters long..   Soem how I doub't that be a issue though.





  Make memblock 1,1000

   s$="HERE IS MY STRING"

  Write_Memblock_String(1,500,S$)

  print Memblock_String(1,500)

wait key
end



Function Write_Memblock_String(ThisBank,address,S$)

 write memblock word ThisBank,Address,len(s$)

 address=address+2
 for lp=1 to len(s$)
  write memblock byte ThisBank,Address,asc(mid$(s$,lp))
  inc address
 next lp

 EndFunction Address


Function Memblock_String(ThisBank,address)
 l=memblock word(ThisBank,Address)
 address=address+2
 c$=""
 for lp=1 to l
  c$=c$+chr$(memblock byte(ThisBank,Address))
  inc address
 next lp
EndFunction c$