Task

Replace every occurring instance of a piece of text in a group of text files with another one.



For this task we want to replace the text   "Goodbye London!"   with   "Hello New York!"   for a list of files.




FUNCTION replaceText RETURNS LOGICAL (
   i_cfile_list   AS CHAR,
   i_cfrom        AS CHAR,
   i_cto          AS CHAR
):
 
   DEF VAR ii     AS INT.
   DEF VAR lcfile AS LONGCHAR.
 
   DO ii = 1 TO NUM-ENTRIES( i_cfile_list ):
      COPY-LOB FROM FILE ENTRY( ii, i_cfile_list ) TO lcfile.
      lcfile = REPLACE( lcfile, i_cfrom, i_cto ).
      COPY-LOB FROM lcfile TO FILE ENTRY( ii, i_cfile_list ).
   END.
 
END FUNCTION. /* replaceText */
 
replaceText( 
   "a.txt,b.txt,c.txt",
   "Goodbye London!",
   "Hello New York!"
).