trim() in dzVents ?  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
willemd
Posts: 649
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

trim() in dzVents ?  [Solved]

Post by willemd »

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?
Doler
Posts: 147
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sint-Oedenrode, Netherlands
Contact:

Re: trim() in dzVents ?

Post by Doler »

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 ''
end
Mark: Domoticz Beta on Raspberry Pi 4 running Debian Bookworm - Z-Stick 7 - RFXCom - P1 - MySensors - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (plugin) - Zwave-js-ui - dzVents - Nodered
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: trim() in dzVents ?

Post by waltervl »

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
willemd
Posts: 649
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: trim() in dzVents ?

Post by willemd »

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.
Doler
Posts: 147
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sint-Oedenrode, Netherlands
Contact:

Re: trim() in dzVents ?

Post by Doler »

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 Beta on Raspberry Pi 4 running Debian Bookworm - Z-Stick 7 - RFXCom - P1 - MySensors - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (plugin) - Zwave-js-ui - dzVents - Nodered
willemd
Posts: 649
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: trim() in dzVents ?

Post by willemd »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest