ReadString() "To the Infinity and beyond"

Feature requests for future versions can be voiced here
Post Reply
User avatar
lazi
Posts: 286
Joined: Fri Feb 25, 2011 12:08 am

ReadString() "To the Infinity and beyond"

Post by lazi » Mon Apr 13, 2015 11:46 am

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. ;)

p-OS
Posts: 89
Joined: Tue Nov 02, 2010 12:56 am

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

Post by p-OS » Mon Apr 13, 2015 3:56 pm

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")

User avatar
lazi
Posts: 286
Joined: Fri Feb 25, 2011 12:08 am

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

Post by lazi » Mon Apr 13, 2015 8:17 pm

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:

Post Reply