Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 362. Find matching string from a list of strings

Created by Jiro Doke

Write a function that returns a string that is a unique match (if it exists) of the string inStr from a list of strings strList.

  • When there are no matches, return an empty string.
  • Match is case-insensitive.
  • Partial match is allowed. (anywhere in the string)
  • Exact match wins over partial matches.
  • When there are multiple partial matches, return an empty string.

Example 1:

   >> inStr = 'ball';
   >> strList = {'ball', 'bell', 'barn'};
   >> outStr = findMatch(inStr, strList)
   outStr =
      ball

Example 2:

   >> inStr = 'EMBER';
   >> strList = {'May', 'June', 'July', 'August', 'September'};
   >> outStr = findMatch(inStr, strList)
   outStr =
      September

Example 3:

   >> inStr = 'Ju';
   >> strList = {'May', 'June', 'July', 'August', 'September'};
   >> outStr = findMatch(inStr, strList)
   outStr =
      ''

Tags

Problem Group

Solution Statistics

28 correct solutions 33 incorrect solutions
Last solution submitted on Jul 11, 2014

Solution Comments