www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SelectSubstringsBetweenStartAndEndPositionsExample.m

    %% Select Substrings Between Start and End Positions
% Create string arrays and select substrings between start and end
% positions that are specified as numbers.
%
% Create a string that contains a name. To select the middle name, specify 
% the seventh and 11th positions in the string.
str = string('Edgar Allen Poe')

%%
newStr = extractBetween(str,7,11)
%%
% Select 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. 

str = string({'Edgar Allen Poe';'Louisa May Alcott'})
%%
newStr = extractBetween(str,[7;8],[11;10])