View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

Be the first to rate this file! 7 Downloads (last 30 days) File Size: 2.19 KB File ID: #43086 Version: 1.3




15 Aug 2013 (Updated )

Replace one or more strings in one or more files safely

| Watch this File

File Information

strrepfile(filename,S1,S2) replaces all occurrences of the string S1 in the file filename with the string S2. S1, S2 may also be cell arrays of strings of the same size, in which case the replacement is performed for each pair by performing a strrep using corresponding elements of the inputs. Alternatively S2 may be a string string with and S1 a cell array, in this case the single string S2 will replace all the strings in S1


strrepfile replaces the string by creating a temporary copy of the file in which the replace is to be performed, replacing it in this file, and copying the file back to the original location for safety. Submission #42877 has the advantage of allowing regex replace, but is not as safe as this version. strrepfile could probably be modified to use regexprep quite easily.


Note strrepfile requires 'samesize.m' my file exchange contribution here:


Find And Replace In Files and Samesize inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Other requirements Requires 'samesize.m' my file exchange contribution here:
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
21 Aug 2013 1.1

Improved and corrected help

06 Sep 2013 1.2

fixed bug in testing for string or cell array of strings filename

11 Sep 2013 1.3

asthetic change to description, no change to file

Contact us