%% Count Occurrences of Pattern
% Count the number of occurrences of the sequence of characters, red, in string arrays.
% Starting in R2017a, you can create a string using double quotes.

str = "paired with red shoes"

%
% To count the occurrences of red, use the count function. In this example, the result is 2 because red is also part of the word paired.

A = count(str,"red")

%
% Create a 2-by-1 string array.

str = ["red green red red blue blue green";
       "green red blue green green blue"]

%
% Count the occurrences of red in each element of str. If str is a string array or cell array of character vectors, then A is a numeric array that has the same size.

A = count(str,"red")

% Copyright 2012 The MathWorks, Inc.