Lasso Soft Inc. > Home

[ file->get ]

Method

The [file->get] method returns either a single character or line depending on the [file] object's read mode. It always returns the next character or line from the current file position, which can be explicity set using the [file->setPosition] method. Note that when returning lines, each line returned does not end with a return or newline character.

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

Retrieve lines from a file

The following example reads the first two lines in the "test.txt" file.

Code

local(my_file) = file('/rhino/test.txt', file_openRead, file_modeLine)
#my_file->doWithClose => {^
    loop(2) => {^
        #my_file->get
        '<br />'
    ^}
^}

Result

"Great Scott!"
"I know. This is heavy."

Read characters from a file

The code below outputs the first 14 characters of a file.

Code

local(my_file) = file('/rhino/test.txt')
#my_file->doWithClose => {^
    loop(14) => {^
        #my_file->get
    ^}
^}

Result

"Great Scott!"

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