LogicMachine Forum
character string - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: character string (/showthread.php?tid=4289)



character string - Chris - 08.10.2022

Hello,

I want to cut part of a value : 


-- value1 --> 11:36:23, Samedi

I want to recover the first part - hour without the day

-- 11:36:23

Thanks.


RE: character string - CristianAgata - 09.10.2022

(08.10.2022, 09:38)Chris Wrote: Hello,

I want to cut part of a value : 


-- value1 --> 11:36:23, Samedi

I want to recover the first part - hour without the day

-- 11:36:23

Thanks.
Hi,
this could work

local value1 = '11:36:23, Samedi'
local data = '%d%d:%d%d:%d%d'
local res = string.match(value1, data)
log(res)


RE: character string - Chris - 09.10.2022

Hello,

Thanks for your answer, but it doesn't work --> value: 0:00:00

https://zupimages.net/viewer.php?id=22/40/8bpk.png

value1 = grp.getvalue("32/1/20")
value2 = grp.getvalue("32/1/21")

local data = '%d%d:%d%d:%d%d'

local res = string.match(value2, data)

grp.write('32/1/30', res)

grp.write('32/1/28', value1)

log(res)


RE: character string - Dré - 09.10.2022

Hi Chris, waht kind of datatype is your "32/1/21" ?

and what result do you get if you do

Code:
value2 = grp.getvalue("32/1/21") log(value2)



RE: character string - CristianAgata - 09.10.2022

(09.10.2022, 11:03)Chris Wrote: Hello,

Thanks for your answer, but it doesn't work --> value: 0:00:00

https://zupimages.net/viewer.php?id=22/40/8bpk.png

value1 = grp.getvalue("32/1/20")
value2 = grp.getvalue("32/1/21")

local data = '%d%d:%d%d:%d%d'

local res = string.match(value2, data)

grp.write('32/1/30', res)

grp.write('32/1/28', value1)

log(res)

Script works if you pass a string, if you pass a table it can't work
Best regard


RE: character string - Chris - 09.10.2022

Hi Dré,

DP : 10. 3 octets heure / jour


User script:6: bad argument #1 to 'match' (string expected, got table)
stack traceback:
[C]: in function 'match'
User script:6: in main chunk


RE: character string - CristianAgata - 09.10.2022

(09.10.2022, 14:06)Chris Wrote: Hi Dré,

DP : 10. 3 octets heure / jour


User script:6: bad argument #1 to 'match' (string expected, got table)
stack traceback:
[C]: in function 'match'
User script:6: in main chunk

Try to change in this this way

local res = string.match(tostring(value2[1], data)
Best regards


RE: character string - Dré - 09.10.2022

try this

Code:
value1 = grp.getvalue('32/1/20') -- time table time = { day = wday, hour = value1.hour, minute = value1.min, second = value1.sec, } -- date table date = { day = value1.day, month = value1.month, year = value1.year, } value1 = string.format("%02d", value1.hour)  .. ":" .. string.format("%02d", value1.min)  .. ":" .. string.format("%02d", value1.sec) log(value1) grp.write('32/1/30', value1) log(value1)


I also see there was use " insteed of '
value1 = grp.getvalue("32/1/20")


RE: character string - Chris - 09.10.2022

Dré your solution works, thank you!
CristianAgata, thank you, I'll try your method soon,
good evening !


RE: character string - admin - 10.10.2022

Next firmware will have an option to hide day and/or seconds for data type 10 (3 byte time / day).

Dré's script is correct. string.format supports multiple arguments so the script can be shorter. There's no different in using single or double quotes in Lua.
Code:
value = event.getvalue() time = string.format('%d:%02d:%02d', value.hour, value.min, value.sec) log(time)