Invokes the passed function for each byte of this File object’s file, passing to the function the character as the first parameter. The method can take an optional second parameter as an Array object (arguments). The elements of this array will be passed to the function as additional parameters. Returns the current position of the pointer in the stream as a Number.

file.each_char(func as Function, arguments? as Array) as Number


  • func. A reference to a function. This function must have been defined with at least one parameter as the current character will be passed to it. This function may have additional parameters defined and these will be passed to it as the contents of the optional arguments array
  • arguments. Optional Array object. Each element of this array will be passed to func as additional parameters after the current byte


Returns the position of the pointer in the stream (file.pos)


The file must be encoded as UTF-8 or else unexpected things will happen.


function listChar(char) {

function prefixChar(char, what) {
    print(what + char)

# Assume file contents are:
# Iron Man
# Hulk
# Thor

var f = File("/Users/garry/Desktop/test.txt")
# Prints:
# I
# r
# o   etc

f.each_char(prefixChar, ["Char: "])
# Prints:
# Char: I
# Char: r
# Char: o   etc