www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ReplaceTextWithinInclusiveAndExclusiveBoundariesExample.m
%% Replace Text within Inclusive and Exclusive Boundaries % Replace text from string arrays within boundaries that are forced to be % inclusive or exclusive. |replaceBetween| replaces the boundaries along with the % text when the boundaries are inclusive. |replaceBetween| does % not replace the boundaries when the boundaries are exclusive. % % Create a string array. Replace the text between sixth and 13th positions, % but do not replace the characters at those positions. str = string('small|medium|large') %% newText = 'regular'; newStr = replaceBetween(str,6,13,newText,'Boundaries','exclusive') %% % Replace the text between two substrings, and also the substrings % themselves. str = string('The quick brown fox jumps over the lazy dog') %% newText = 'red bird flies'; newStr = replaceBetween(str,'brown','jumps',newText,'Boundaries','inclusive')