www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SelectSubstringsBeforePositionExample.m
%% Select Substrings Before Position % Create strings before specified positions. % % Create a string that contains a name. str = string('Edgar Allen Poe') %% % Select the substring before the sixth character. newStr = extractBefore(str,6) %% % Select substrings from each element of a string array. When you specify % different positions with numeric arrays, they must be the same size as the % input string array. str = string({'Edgar Allen Poe';'Louisa May Alcott'}) newStr = extractBefore(str,[6;7]) %% % Select substrings from each element and specify the same position. newStr = extractBefore(str,12)