Page 1 of 1

ReadString() "To the Infinity and beyond"

Posted: Mon Apr 13, 2015 11:46 am
by lazi
I wish I could use ReadString() without knowing the length.
Maybe a #NIL as length could mean that should read the bytes until it reach the end of file or the end of the universe. ;)

Re: ReadString() "To the Infinity and beyond"

Posted: Mon Apr 13, 2015 3:56 pm
by p-OS
A Hollywood string is not limited to characters, it can also contain binary data. As documentation explicitly states ReadString is also meant for reading parts of a binary file to memory. Thus it is important to give length. If you just want to read complete file in to memory, you could use either

Code: Select all

size =FileSize("myfilename")
fh=OpenFile(Nil,"myfilename")
mystring=ReadString(fh,size)
CloseFile(1)
or more easily:

Code: Select all

mystring=FileToString("myfilename")

Re: ReadString() "To the Infinity and beyond"

Posted: Mon Apr 13, 2015 8:17 pm
by lazi
Thanks!

The first method is known by me, but overlooked the FileToString() function.

Hollywood is so huge that my 45 years old head hardly can fight with it :lol: