switchmatch(
KEY
,
CASE
,
VALUE
,
...
,
DEFAULT
)

The switchmatch( function chooses from a list of values based on a wildcard match.


Parameters

This function has four required parameters:

key – The value that controls which option is selected.

case – The wildcard value that must match the key value to select this option. This may contain the * and ? wildcard characters, see the match operator to learn more about wildcards.

value – The value associated with this case.

– One or more additional case/value pairs may be inserted here

default – The default value that will be used if the key does not match any of the cases.


Description

The switchmatch( function makes it easy to choose from a list of values. The first parameter is the key. The function attempts to match the key value with each of the case values (from left to right). Each match can include the * and ? wildcard characters. If it finds a match, the function returns the corresponding value. If there are no matches at all, the default value is returned. (Each case/value pair is shown on a separate line in the examples below, but this is not necessary.)

In the examples below, the result is returned based on just the first character, or the first two characters.

switchmatch("Gold",
    "g*",79,
    "s*",47,
    "c*",29,
    "t*",50,
     0) ☞ 79
switchmatch("Copper",
    "g*",79,
    "s*",47,
    "c*",29,
    "t*",50,
     0) ☞ 29
switchmatch("Carbon",
    "g*",79,
    "s*",47,
    "ca*",6,
    "co*",29,
    "t*",50,
     0) ☞ 6
switchmatch("Helium",
    "g*",79,
    "s*",47,
    "c*",29,
    "t*",50,
     0) ☞ 0

Note: The switchmatch( function is not case sensitive. Use the switchmatchexact( function if you need to distinguish between upper and lower case.


See Also


History

VersionStatusNotes
10.0NewNew in this version.