[SOLVED] Count words in String

Hi Together,

I am using the latest OH2.3 Version as Openhabian. I have an Question to the Rules:

var i = -1
while((i=i+1) < 3) {
val txtv = receivedCommand.toString.toLowerCase.split("und")
val txt = txtv.get(i).toLowerCaset
is there any possibility to coutnt the ammount of “und” in my String and set the “i” to this ammount. Actual i am limited to 3 or whatever I type in my Code.
Hope someone can help, thanks in Advantage :slight_smile:

Greetings Andy

There you go:

val txtv = receivedCommand.toString.toLowerCase.split("und")
var i = txtv.length - 1

Wunderschöne Lösung.:sunglasses:

Not quite! A one liner is possible:

var i = receivedCommand.toString.toLowerCase.split("und").length - 1
1 Like

Hey Vincent,
thanks a lot, works great :slight_smile: made my day.

Greetings Andy

1 Like