MAP transform & split not working as expected

  • Platform information:

    • Hardware: Raspberry Pi 3
    • OS: Openhabian 2.5.0-1
    • Java Runtime Environment: OpenJDK Runtime Environment (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
    • openHAB version: 2.5.0 Release Build
  • Please post configurations (if applicable):

    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

Rule

val info = transform("MAP", "scenes.map", "wit").split("$")
logInfo("mqtt", "gScene received command: " + info.get(0))  

Map

wit = 3$Scheme$0$Speed$10$White$100
warm = 4$Scheme$0$Speed$10$White$100$Color$32,64,100
party = 2$Scheme$4$Speed$5

Log

2019-12-28 19:08:01.058 [INFO ] [.eclipse.smarthome.model.script.mqtt] - gScene received command: 3$Scheme$0$Speed$10$White$100

I would expect output of 3, instead I get the entire line.

I used this post as starting point.

Where is your item config and do you have the transformation service installed?

The transformation works fine though, it seems the split is not working correctly, and can’t really tell why not.
What happens if you just log the value of info?

Java’s String.split() method takes a regex argument. So you probably need to escape the $ to prevent it from being treated as an end-of-line marker.

Correct!
Changed the seperator character to “|” in the map and it worked like a charm.
Thanks!

Is there actually a way of getting the count of the number of elements after the split?
Now it at the start of everly map line order to loop the elements.
Not really elegant.

Nevermind my last question.
This seems the solution to my problem.