Navigation

Operators and Keywords

Function List:

C++ API

: validstr = validatestring (str, strarray)
: validstr = validatestring (str, strarray, funcname)
: validstr = validatestring (str, strarray, funcname, varname)
: validstr = validatestring (…, position)

Verify that str is an element, or substring of an element, in strarray.

When str is a character string to be tested, and strarray is a cellstr of valid values, then validstr will be the validated form of str where validation is defined as str being a member or substring of validstr. This is useful for both verifying and expanding short options, such as "r", to their longer forms, such as "red". If str is a substring of validstr, and there are multiple matches, the shortest match will be returned if all matches are substrings of each other. Otherwise, an error will be raised because the expansion of str is ambiguous. All comparisons are case insensitive.

The additional inputs funcname, varname, and position are optional and will make any generated validation error message more specific.

Examples:

validatestring ("r", {"red", "green", "blue"})
⇒ "red"

validatestring ("b", {"red", "green", "blue", "black"})
⇒ error: validatestring: multiple unique matches were found for 'b':
   blue, black

See also: strcmp, strcmpi, validateattributes, inputParser.

Package: octave