Search and replace a word of text file from GUI

6 views (last 30 days)
I need to parse a text file in way like what find and replace (strrep) function does in the string. It actually has to get a word (‘new’) as input from the GUI, search within the text file for a special word (‘old’) and replace it.
Any help would be greatly appreciated

Accepted Answer

Stephen23
Stephen23 on 29 Feb 2016
Edited: Stephen23 on 29 Feb 2016
A text file is a string. So just read the file using fileread, and perform your operations on it:
str = fileread(filename);
str = strrep(str,old,new);
  7 Comments
Saeed Soltani
Saeed Soltani on 3 Mar 2016
Thanks a lot Stephen, that was great help :)

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!