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

    %% Insert Text Before Substring
% Create string arrays and insert text before substrings.
%
% Create a string. Insert a comma before each space character in the
% string. The |insertBefore| function inserts text before each matching
% substring.
str = string('bread cheese wine')

%%
newStr = insertBefore(str,' ',',')

%%
% Insert substrings into each element of a string array. When you specify 
% different substrings as positions, they must be contained
% in a string array or a cell array that is the same size as |str|.
str = string({'The quick fox jumps';'over the dog'})

%%
newStr = insertBefore(str,{' fox';' dog'},{' brown';' lazy'})