Seed7 - The extensible programming language
Seed7 FAQ Manual Screenshots Examples Libraries Algorithms Download Links
Examples echo args file in string simple clock count words subtype map function generic func declare stmt template operator 3-way if
Read a file into a string
 previous   up   next 

This example program interprets the arguments as file names and replaces the string "dog" by "cat" in the corresponding files

$ include "seed7_05.s7i";       # Standard Seed7 library
  include "getf.s7i";           # Import the getf and putf functions

const proc: main is func
    var string: file_name is "";
    for file_name range argv(PROGRAM) do
      putf(file_name, replace(getf(file_name), "dog", "cat"));
    end for;
  end func;

The function getf reads the complete file with the name 'file_name' into a string and returns it. Since strings can have any length and can contain any data (even zero bytes) this is possible. The function replace replaces "dog" by "cat" and after that the function putf writes the string back to the file with the name 'file_name'. The functions getf and putf are defined in "getf.s7i".

 previous   up   next