MATLAB: Find strings that contains a specific number of a substrings

stringssubstrings

str = { 'anna', 'jeniffer', 'carla'};
Is there a function that will tell me the index of the names that have 2 'a'. So return
[1 0 1]

Best Answer

  • cellfun(@(s) sum(s=='a')==2, str)