Is it possible to only use a part of a variable? I have a variable filled with like “aabbcc”. Now I only want to use the “bb” (maybe substring?)
-
Use part of a variable (substring?)
-
@Gratizzz I don’t think this is possible right now or I am missing something on the undocumented magic of variable expressions.
If it is not supported it might be added by providing a function, e.g. a function to create a substring from a given variable value or more generally a function which the possibility to match a regular expression and returning the matched string (which may be a substring) of the given value.
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
you can use node-red for this. There you can create a function (in JavaScript) that does this
-
@rikki78 thanks mate! I’ll try this out
-
@Gratizzz Following up on my previous post there is no undocumented magic for variable expressions. Thus, I have implemented a subString function which can be used as part of variable expressions. A regular expression (optionally with capture groups and flags) can be provided to filter the substring. Say, you want to return the third and forth character of your variable
$someVariable = “aabbcc"
this can be done as follows:subString($someVariable, "..(..)")
.The feature will be published with the next release of pimatic.
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
very nice!! marcus can you please provide some more examples how to use this new feature then?
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebookmake it so !
-
@mwittig wow! cooool thanks mate I’ll try it out when possible
-
@Gratizzz You’re welcome! The feature has been released as part of pimatic 0.9.39.
As @leader21 suggested, I have compiled a few usage examples. As we currently don’t have a spot for the documentation of variable functions, I have started a “how to” article on using String Expressions and String Functions for Variables & Rules.
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law