%% Replace Substrings Between Start and End Positions
% Create string arrays and replace substrings between start and end positions that are specified as numbers.
% Starting in R2017a, you can create strings using double quotes. Create a string that contains a name. To replace the middle name, specify the seventh and 11th positions in the string.

str = "Edgar Allen Poe"

%

newStr = replaceBetween(str,7,11,'A.')

%
% Replace substrings from each element of a string array. When you specify different start and end positions with numeric arrays, they must be the same size as the input string array. The replacement text also must be in a string array or a cell array of the same size.

str = ["Edgar Allen Poe";"Louisa May Alcott"]

%

newText = ["A.";"M."];
newStr = replaceBetween(str,[7;8],[11;10],newText)

% Copyright 2012 The MathWorks, Inc.