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

    %% Insert Substring Before Position
% Create string arrays and specify positions to insert substrings.
%
% Create a string that contains a name.
str = string('James Maxwell')

%%
% Insert a substring before the seventh character.
newStr = insertBefore(str,7,'Clerk ')
%%
% Insert substrings into 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({'James Maxwell';'Carl Gauss'})
newStr = insertBefore(str,[7;6],{'Clerk ';'Friedrich '})