Does dzvents have a trim() function? I cannot find it in the documentation.
I am importing data and one of the fields has a trailing space that I want to remove.
I tried the stringSplit function with space as separator but this did not achieve the result.
Currently I am forcing conversion to a number and then converting back to a string to achieve this.
Does a trim() function exist?
trim() in dzVents ? [Solved]
Moderator: leecollings
-
Doler
- Posts: 194
- Joined: Friday 31 July 2015 21:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Sint-Oedenrode, Netherlands
- Contact:
Re: trim() in dzVents ?
Don't know if dzvents has this function but in case not:
Code: Select all
-- Trim a string
stringTrim = function(s)
return s:match'^%s*(.*%S)' or ''
endMark: Domoticz latest Beta on Virtual machine (Proxmox) running Debian Trixie - Z-Stick 7 - RFXCom - P1 - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (latest, docker) via python plugin - Zwave-js-ui (latest, docker) - dzVents - Nodered
- waltervl
- Posts: 7011
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2026.3
- Location: NL
- Contact:
Re: trim() in dzVents ?
Dzvents has no trim function, neither does Lua but there are lots of ways to create one: http://lua-users.org/wiki/StringTrim
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
willemd
- Posts: 791
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2026.3
- Location: The Netherlands
- Contact:
Re: trim() in dzVents ?
Thank you both, one solution is enough 
What kind of programming language is used for that function definition? I don't recognise it and can't decifer the logic. It works but I don't see why.
What kind of programming language is used for that function definition? I don't recognise it and can't decifer the logic. It works but I don't see why.
-
Doler
- Posts: 194
- Joined: Friday 31 July 2015 21:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Sint-Oedenrode, Netherlands
- Contact:
Re: trim() in dzVents ?
It's Lua. There is a little error in the function (sorry for that): 'match' should be 'string.match'. I guess you can recognize it now.
Mark: Domoticz latest Beta on Virtual machine (Proxmox) running Debian Trixie - Z-Stick 7 - RFXCom - P1 - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (latest, docker) via python plugin - Zwave-js-ui (latest, docker) - dzVents - Nodered
-
willemd
- Posts: 791
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2026.3
- Location: The Netherlands
- Contact:
Re: trim() in dzVents ?
Assembler, basic, algol, pascal, lisp, cobol, various 4gl's, python, dzVents, probably forgetting a few .... I am trying not to add Lua to it. 
Thank you for your solution.
Thank you for your solution.