switch - luxembourg/muxcode-clm GitHub Wiki

SWITCH()

FUNCTION: switch(<str>[,<pat1>,<res1>]...[,<dflt>])

The switch function compares <str> against each pattern, <patI>, returning the result, <resI> that corresponds to the first pattern that matches <str>. If none match, then the default result, <dflt>, is returned.

Before <resI> is evaluated for return, #$ is substituted with the value of <str>. In this way, <resI> has a short-hand way of getting at the <str> that matched it's corresponding pattern.

Patterns may include * and ?. * matches any number of characters, and ? matches any 1 character. Instead of pattern matching, it is also possible to compare the alphabetic or numeric value of <str> with <pat> by using the < and > operators.

Example: > say switch(c,a,A,b,B,c,C,d,D,E) You say, "C" > say switch(f,a,A,b,B,c,C,d,D,E) You say, "E" > say switch(cab,a,A,b,B,c,C,d,D,E) You say, "A" > say switch(f,a,A,b,B,c,C,d,D) You say, ""

Related Topics: @switch, match, ifelse, case