This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

character string
#1
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.
Reply
#2
(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)
Reply
#3
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)
Reply
#4
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)
Reply
#5
(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
Reply
#6
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
Reply
#7
(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
Reply
#8
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")
Reply
#9
Dré your solution works, thank you!
CristianAgata, thank you, I'll try your method soon,
good evening !
Reply
#10
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)
Reply


Forum Jump: