Logic Machine Forum
Replace . with , - Printable Version

+- Logic Machine 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: Replace . with , (/showthread.php?tid=3628)



Replace . with , - Trond Hoyem - 18.10.2021

Hi

I am struggling a bit to do a replacement inside a value. What I want to do is make a log of temperatures and write this as CSV to an FTP-server at an external PC. All this works fine, but when I open the CSV in Excel, then MS in their infinite wisdom has decided that numbers containing '.' should be automatically seen as a date. 

I am able to fix this myself in Excel, but in this case the users are not familiar with the use of computers, or any device connected to power, and so I must make it idiot-proof.

What I would like to do is to replace the '.' with a ',' in the value before adding it to the CSV. But I am not able to do this.

If I use string.gsub(), all characters in the value is replaced with ',', and I get values like ',,,,'. I tested a bit with string.find() to see how the '.' is read, and it seems to be some kind og 'magic character'? If I use the 'plain' parameter in string.find() I am able to find the '.'.

So, in short; how do I do this?


RE: Replace . with , - admin - 18.10.2021

Dot is a special symbol which means "any character". Add % before the dot and it will work:
Code:
value = value:gsub('%.', ',')



RE: Replace . with , - Trond Hoyem - 19.10.2021

(18.10.2021, 14:40)admin Wrote: Dot is a special symbol which means "any character". Add % before the dot and it will work:
Code:
value = value:gsub('%.', ',')

OK, thanx.
Will test this tomorrow morning when I am at the SL again.


RE: Replace . with , - Trond Hoyem - 20.10.2021

(18.10.2021, 14:40)admin Wrote: Dot is a special symbol which means "any character". Add % before the dot and it will work:
Code:
value = value:gsub('%.', ',')

Worked like a charm.

Thanks for help, once again!