Hello
I'm running Domoticz 4.1214. Using dzVents: I'm trying to replace a character by another one in a string. Can anyone lead me towards the solution?Thank you
Replace a character in a string [Solved]
Moderator: leecollings
-
Number8
- Posts: 374
- Joined: Friday 23 May 2014 7:55
- Target OS: Linux
- Domoticz version: 2022.1
- Location: Saint Pierre de Jards
- Contact:
Replace a character in a string
Debian buster on NUC and three RPi with buster.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Replace a character in a string
Have a look at this siteNumber8 wrote: Saturday 23 November 2019 10:57 I'm trying to replace a character by another one in a string. Can anyone lead me towards the solution ?
You will find something like below ( and a lot of other useful information on Lua)
Code: Select all
local a = 'domoticz'
local b = a:gsub('d','D')
print(b) --> Domoticz
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
Number8
- Posts: 374
- Joined: Friday 23 May 2014 7:55
- Target OS: Linux
- Domoticz version: 2022.1
- Location: Saint Pierre de Jards
- Contact:
Re: Replace a character in a string
As a matter of fact I need to replace a dot '.' by a comma ','. So far it does not work. Is the comma considered as a special character that I should declare another way?
Debian buster on NUC and three RPi with buster.
-
zicht
- Posts: 300
- Joined: Sunday 11 May 2014 11:09
- Target OS: Windows
- Domoticz version: 2023.1+
- Location: NL
- Contact:
Re: Replace a character in a string
you should escape it
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Replace a character in a string [Solved]
You could do yourself a big favor by trying to use a search engine before asking here. The first hit when searching for 'special character Lua'Number8 wrote: Saturday 23 November 2019 11:51 As a matter of fact I need to replace a dot '.' by a comma ','. So far it does not work. Is the comma considered as a special character that I should declare another way?
Shows this site where you can read how to escape these special chars.
Code: Select all
> a = 'domoticz. dzVents'
b = a:gsub('%.',',')
print(b) --> domoticz, dzVentsDebian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
Number8
- Posts: 374
- Joined: Friday 23 May 2014 7:55
- Target OS: Linux
- Domoticz version: 2022.1
- Location: Saint Pierre de Jards
- Contact:
Re: Replace a character in a string
Thanks @waaren. This is what I did at the first place, I was indeed trying to search for escape in the tutorial without success.
Debian buster on NUC and three RPi with buster.
Who is online
Users browsing this forum: No registered users and 1 guest