This shows you the differences between two versions of the page.
— |
docu_extract [2018/08/10 13:05] (current) Niek created |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | =====Extract a value from a string of name=value pairs (http query string)===== | ||
+ | The EXTRACT function will look for a given key in a string with key=value pairs. | ||
+ | Such a string can be a device value or a fixed string and will typically look like this: | ||
+ | |||
+ | <code> | ||
+ | key1=value1&key2=value2&.... | ||
+ | </code> | ||
+ | |||
+ | Values can be strings or numbers | ||
+ | |||
+ | If the given key is found, its value is returned. If the key cannot be found, the function by default returns "*not found*". | ||
+ | |||
+ | Using a third parameter this default can be set to a value of your own choice. This can be either a fixed string or number, or the key itself. | ||
+ | |||
+ | ====Examples==== | ||
+ | |||
+ | <code> | ||
+ | IF EXTRACT(mylabel.label, foo) == bar THEN .... (searches for key "foo" in mylabel.label and returns the corresponding value, or *not found* if the key "foo" is absent) | ||
+ | |||
+ | IF EXTRACT(mylabel.label, foo, failed) != failed THEN .... (searches for key "foo" in mylabel.label and returns the corresponding value, or "failed" if the key "foo" is absent) | ||
+ | |||
+ | IF EXTRACT(mylabel.label, foo, '$_KEY') == bar THEN .... (searches for key "foo" in mylabel.label and returns the corresponding value, or "foo" if the key "foo" is absent) | ||
+ | |||
+ | IF 1==1 THEN label DEVICE mylabel TO 'some text' COLOR EXTRACT('on=red&off=green', myswitch.state) .... (searches for state of myswitch ("on" or "off") in "on=red&off=green" and sets the color to the corresponding value) | ||
+ | |||
+ | </code> |