Xbasic

*PATTERN_LOOKUP Function

Syntax

Result as C = *PATTERN_LOOKUP(text as c,key as c,pattern as c,otherwise as c)

Arguments

Result

The value returned by the function.

text

Contains a delimited list to search for a pattern. The delimiter is the last character in the Pattern string.

key

The value to find in Text.

pattern

A string with two "*" placeholders in it. The first placeholder encountered is the Key. The second is the Result to return. The Pattern must have one or more characters between the two placeholders, and a list delimiter at the beginning, at the end, or at both the beginning and end of the Pattern string.

otherwise

The value to return if the Key is not found in the list.

Description

Looks up a value matching a key on text, if none found return 'otherwise' condition.

Discussion

The *PATTERN_LOOKUP() function examines Text for a Key value. If the Key is not found, the function returns Otherwise.

Example

? *pattern_lookup("one=1,two=2,three=3","two","*=*,","0") 
 = "2" 

 ? *pattern_lookup("=1,=2,=3","four","=*,","0") 
 = "0" 

 ? *pattern_lookup("=1,=2,=3","three","=*,","0") 
 = "3"

Limitations

The Key argument is case sensitive.

See Also