Lasso Soft Inc. > Home

[ file_modechar ]

Method

The [file_modechar] constant returns a value that the [file] type uses to set the file get mode to read a character at a time.

  • Syntax
file_modechar

file('/path/to/a/file', io_file_o_rdonly, file_modechar)
Examples
  • Beginner

Determine if a file contains a specific character

The code below reads through a file a character at a time counting the number of times the letter 'o' appears in the file.

Code

// '/path/to/file.txt' contains the following contents:
// I love the Lasso Rhino!

local(f) = file('/path/to/file.txt', io_file_o_rdonly, file_modeChar)
handle => { #f->close }

local(my_count)  = 0
local(next_char) = #f->get
while(#next_char) => {
    if(#next_char == 'o' or #next_char == 'O') => {
        #my_count += 1
    }
    #next_char = #f->get
}
#my_count

Result

3

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