%% Split String and Find Unique Words
% To find the unique words in a string, split it on space characters and call the unique function.
% First, create a string scalar.

str = "A horse! A horse! My kingdom for a horse!"

%
% Remove the exclamation point.

str = erase(str,"!")

%
% Convert all letters in str to lowercase characters.

str = lower(str)

%
% Split str on space characters using the split function. split discards the space characters and returns the result as a string array.

str = split(str)

%
% Find the unique words in str using the unique function.

str = unique(str)

% Copyright 2012 The MathWorks, Inc.