Problem 362. Find matching string from a list of strings
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 =
''
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers258
Suggested Problems
-
2335 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
543 Solvers
-
Set the array elements whose value is 13 to 0
1381 Solvers
-
Cell Counting: How Many Draws?
2142 Solvers
-
Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.
943 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!