%% Replace Text Between Substrings
% Create string arrays and replace text that occurs between substrings.
% Starting in R2017a, you can create strings using double quotes.

str = "The quick brown fox"

%
% If you are using R2016b, create string arrays using the string function instead of double quotes.
% Replace the text that occurs between the substrings quick and fox. The replaceBetween function replaces the text but does not replace quick or fox in the output.

newStr = replaceBetween(str,"quick "," fox","red")

%
% Replace substrings from each element of a string array. When you specify different substrings as start and end indicators, they must be contained in a string array or a cell array that is the same size as str. The replacement text also must be in a string array or a cell array of the same size.

str = ["The quick brown fox jumps";"over the lazy dog"]

%

newText = ["red";"sleeping"];
newStr = replaceBetween(str,["quick ";"the "],[" fox";" dog"],newText)

% Copyright 2012-2020 The MathWorks, Inc.