www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SplitTextStringwithMultipleDelimitersExample.m
%% Split Character Vector with Multiple Delimiters %% % Split a character vector on |' '| and |'ain'|, treating multiple delimiters as one. % Specify multiple delimiters in a cell array of character vectors. str = 'The rain in Spain stays mainly in the plain.'; [C,matches] = strsplit(str,{' ','ain'},'CollapseDelimiters',true) %% % Split the same character vector on whitespace and on |'ain'|, using regular % expressions and treating multiple delimiters separately. [C,matches] = strsplit(str,{'\s','ain'},'CollapseDelimiters',... false, 'DelimiterType','RegularExpression') %% % In this case, |strsplit| treats the two delimiters separately, so empty % character vectors appear in output |C| between the consecutively matched delimiters.