Lasso Soft Inc. > Home

[ file->readString ]

Method

The [file->readString] method reads string data from a file. If a character set has been set using [file->setEncoding] then that character set is used to translate data from the file into Lasso's string format. Alternately, [file->readBytes] can be used to read a byte stream from a file.

The [file] type implements [trait_readString] which provides the [trait_readString->readString] method. This means that you can call [file->readString] with a single parameter which specifies how many bytes of data to read from the file. If this parameter is not specified, the method reads the entire file. In files that contain multi-byte data this number may not correspond to the number of characters which will be read from the file.

  • Syntax
local(f) = file(...)
#f->readString
Examples
  • Beginner

Display the contents of a file

The code below displays the contents of a file, encoding all line breaks as '<br />' tags.

Code

local(my_file) = file('/rhino/test.txt', file_openRead, file_modeLine)
#my_file->doWithClose => {^
    encode_break(#my_file->readString)
^}

Result

"Great Scott!"
"I know. This is heavy."
"Manure. I hate manure."

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft