Examples |
|
Read a file into a string |
|
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 local var string: file_name is ""; begin 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".
|
|