How to resolve the algorithm Globally replace text in several files step by step in the Run BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Globally replace text in several files step by step in the Run BASIC programming language
Table of Contents
Problem Statement
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.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Globally replace text in several files step by step in the Run BASIC programming language
Source code in the run programming language
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
You may also check:How to resolve the algorithm Resistor mesh step by step in the Perl programming language
You may also check:How to resolve the algorithm Phrase reversals step by step in the C++ programming language
You may also check:How to resolve the algorithm Associative array/Creation step by step in the UnixPipes programming language
You may also check:How to resolve the algorithm Retrieve and search chat history step by step in the Julia programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the Perl programming language