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.




file$(1) ="data1.txt"
file$(2) ="data2.txt"
file$(3) ="data3.txt"
 
for i = 1 to 3
    open file$(i) for input as #in
        fileBefore$ = input$( #in, lof( #in))
    close #in
 
    fileAfter$ = strRep$(fileBefore$, "Goodbye London!", "Hello New York!")
    open "new_" +  file$(i) for output as #out
        print #out,fileAfter$;
    close #out
next i
end
 
' --------------------------------
' string replace - rep str with
' --------------------------------
FUNCTION strRep$(str$,rep$,with$)
ln  = len(rep$)
ln1 = ln - 1
i   = 1
while i <= len(str$)
    if mid$(str$,i,ln) = rep$ then
        strRep$ = strRep$ + with$
        i = i + ln1
    else
        strRep$ = strRep$ + mid$(str$,i,1)
    end if
i = i + 1
WEND
END FUNCTION