split string power

Moderator: leecollings

Post Reply
jandoedel99
Posts: 12
Joined: Tuesday 18 April 2017 21:55
Target OS: -
Domoticz version:
Contact:

split string power

Post by jandoedel99 »

I have a string with hold the data of my smartmeter. I need the 5e element. How do i separete that element.
1508914;1483046;446236;1202730;3018;0

Thanks
SweetPants

Re: split string power

Post by SweetPants »

Try this:

str = "1508914;1483046;446236;1202730;3018;0"

words = {}
for word in str:gmatch("([^;]+)") do table.insert(words, word) end
print (words[5])
jandoedel99
Posts: 12
Joined: Tuesday 18 April 2017 21:55
Target OS: -
Domoticz version:
Contact:

Re: split string power

Post by jandoedel99 »

Thanks this works.
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: split string power

Post by freijn »

str = "1508914;1483046;446236;1202730;3018;0"

local result = mw.text.split(str,";")
-- result[4] will give "3018"
SweetPants

Re: split string power

Post by SweetPants »

freijn wrote: Wednesday 27 December 2017 20:31 str = "1508914;1483046;446236;1202730;3018;0"

local result = mw.text.split(str,";")
-- result[4] will give "3018"
Are you sure this works?
mvrossum
Posts: 6
Joined: Wednesday 06 September 2017 22:55
Target OS: Linux
Domoticz version: V4.10301
Location: Almere
Contact:

Re: split string power

Post by mvrossum »

Thanks @SweetPants
Fibaro HC2, 2 x Raspberry Pi, Xiaomi, Toon, Homey en nogal wat Z-Wave en ZigBee spul.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest