How can MATLAB find and replace a word in a text that contains multiple lines?
Show older comments
E.g. if there is a text file with 57 lines and I want a small change of a word in line 54.
2 Comments
dpb
on 23 Dec 2017
If you do mean in a text file, then "Houston, we (may) have a problem!" as text files are sequential and any change in the chosen word that changes its length will change the length of the file. Also, writing to a file has the effect of truncating the file from that point forward.
The only (practical) way to do this is to read the file into memory and make the change there and then rewrite the whole file.
GEORGIOS BEKAS
on 23 Dec 2017
Accepted Answer
More Answers (0)
Categories
Find more on App Building in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!