openHAB 2.4.0~20181105174706-1 (Build #1413)
Is it possible to get a count of the number of “segments” when using myString.split(";")
so I know how many there are?
I have been using a concatenated string to pass two parameters to a Rule as
myItem.postUpdate("parameter1;parameter2")
and having the Rule trigger on the change in the Item.
I want to update my logic to have an optional third parameter and have the Rule “extract” the third parameter if it’s present or set a hard-coded value if the parameter is not passed. The problem is that if a third parameter is not present, a .get(2)
raises an exception… as it should.
I know that there are lots of ways I could pass parameters to the Rule… but I’ve already gone down this route (i.e., passing parameters as a concatenated string) and used it in many Rules. I could have a different method to pass this third optional parameter, of course. But then the coding is inconsistent.
Is there a “concise” method of querying the number of concatenated segments or counting the number of delimiters present?
Thanks.
Mike