%% Split Strings at Whitespace and Rejoin Them
% Split names in a string array at whitespace characters. Then reorder the strings and join them so that the last names precede the first names.
% Create a 3-by-1 string array containing names. Starting in R2017a, you can create strings using double quotes.

names = ["Mary Butler";
         "Santiago Marquez";
         "Diana Lee"]

%
% If you are using R2016b, create string arrays using the string function instead of double quotes.
% Split names at whitespace characters, making it a 3-by-2 string array.

names = split(names)

%
% Switch the columns of names so that the last names are in the first column. Add a comma after each last name.

names = [names(:,2) names(:,1)];
names(:,1) = names(:,1) + ','

%
% Join the last and first names. The join function places a space character between the strings it joins. After the join, names is a 3-by-1 string array.

names = join(names)

% Copyright 2012-2020 The MathWorks, Inc.